TransferDataStore: fix initial transfer speed history population

This commit is contained in:
Jesse Chan
2020-10-25 20:26:40 +08:00
parent a317696751
commit 9875883fb3
2 changed files with 16 additions and 10 deletions
@@ -6,7 +6,12 @@ import type {TransferDirection, TransferHistory, TransferSummary} from '@shared/
export const TRANSFER_DIRECTIONS: Readonly<Array<TransferDirection>> = ['download', 'upload'] as const;
class TransferDataStoreClass {
transferRates: TransferHistory = {download: [], upload: [], timestamps: []};
transferRates: TransferHistory = {
download: new Array(30).fill(0),
upload: new Array(30).fill(0),
timestamps: new Array(30).fill(Date.now()),
};
transferSummary: TransferSummary = {
downRate: 0,
downThrottle: 0,
@@ -25,13 +30,16 @@ class TransferDataStoreClass {
const upload = this.transferRates.upload.slice();
const timestamps = this.transferRates.timestamps.slice();
download.shift();
download.push(this.transferSummary.downRate);
upload.shift();
upload.push(this.transferSummary.upRate);
timestamps.shift();
timestamps.push(Date.now());
if (timestamps.length > 30) {
download.shift();
upload.shift();
timestamps.shift();
}
this.transferRates = {download, upload, timestamps};
}
+4 -6
View File
@@ -152,12 +152,10 @@ class HistoryService extends BaseService<HistoryServiceEvents> {
handleFetchTransferSummarySuccess(nextTransferSummary: TransferSummary) {
const summaryDiff = jsonpatch.compare(this.transferSummary, nextTransferSummary);
if (summaryDiff.length > 0) {
this.emit('TRANSFER_SUMMARY_DIFF_CHANGE', {
diff: summaryDiff,
id: Date.now(),
});
}
this.emit('TRANSFER_SUMMARY_DIFF_CHANGE', {
diff: summaryDiff,
id: Date.now(),
});
this.errorCount = 0;
this.transferSummary = nextTransferSummary;