fix(statistics): preserve private account history safely
This commit is contained in:
@@ -85,6 +85,7 @@ import {
|
||||
addStatisticsOutcomeInPlace,
|
||||
createStatisticsLedger,
|
||||
loadStatisticsLedger,
|
||||
normalizeStatisticsLedger,
|
||||
projectStatisticsLedger,
|
||||
saveStatisticsLedger,
|
||||
seedStatisticsDayProviderBytes
|
||||
@@ -2624,7 +2625,7 @@ export class DownloadManager extends EventEmitter {
|
||||
};
|
||||
}
|
||||
|
||||
public getStats(now = nowMs()): DownloadStats {
|
||||
public getStats(now = nowMs()): DownloadStats {
|
||||
const itemCount = this.itemCount;
|
||||
if (this.statsCache && this.session.running && itemCount >= 500 && now - this.statsCacheAt < 1500) {
|
||||
return this.statsCache;
|
||||
@@ -2649,8 +2650,12 @@ export class DownloadManager extends EventEmitter {
|
||||
};
|
||||
this.statsCache = stats;
|
||||
this.statsCacheAt = now;
|
||||
return stats;
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
public getStatisticsLedgerForBackup(now = nowMs()): StatisticsLedger {
|
||||
return normalizeStatisticsLedger(this.statisticsLedger, now);
|
||||
}
|
||||
|
||||
public getLiveTotalRuntimeMs(now = nowMs()): number {
|
||||
return Math.max(0, this.runtimePersistedTotalMs + Math.max(0, now - this.runtimePersistedAt));
|
||||
@@ -8234,12 +8239,16 @@ export class DownloadManager extends EventEmitter {
|
||||
}
|
||||
const recordedAt = nowMs();
|
||||
const effectiveProvider = resolveMegaDebridProvider(this.settings, provider) || provider;
|
||||
const accountStatus = providerAccountId ? this.settings.debridAccountStatuses[providerAccountId] : undefined;
|
||||
const statisticsAccountLabel = accountStatus?.username?.trim()
|
||||
|| accountStatus?.email?.trim()
|
||||
|| providerAccountLabel;
|
||||
addStatisticsBytesInPlace(this.statisticsLedger, effectiveProvider, byteDelta, recordedAt);
|
||||
this.rollingAccountStatistics.record(
|
||||
effectiveProvider,
|
||||
byteDelta,
|
||||
providerAccountId,
|
||||
providerAccountLabel,
|
||||
statisticsAccountLabel,
|
||||
recordedAt
|
||||
);
|
||||
this.statisticsDirty = true;
|
||||
|
||||
Reference in New Issue
Block a user