mirror of
https://github.com/zoriya/flood.git
synced 2026-06-02 02:56:05 +00:00
TransferDataStore: fix initial transfer speed history population
This commit is contained in:
@@ -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};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user