Fix session runtime reset

This commit is contained in:
Sucukdeluxe 2026-03-09 06:06:39 +01:00
parent f447c0f37a
commit 4374119f9e
2 changed files with 33 additions and 2 deletions

View File

@ -1822,13 +1822,15 @@ export class DownloadManager extends EventEmitter {
} }
public resetSessionStats(): void { public resetSessionStats(): void {
const now = nowMs();
this.session.totalDownloadedBytes = 0; this.session.totalDownloadedBytes = 0;
this.sessionDownloadedBytes = 0; this.sessionDownloadedBytes = 0;
this.sessionCompletedFiles = 0; this.sessionCompletedFiles = 0;
this.session.runStartedAt = this.session.running ? nowMs() : 0; this.session.runStartedAt = this.session.running ? now : 0;
this.appSessionStartedAt = now;
this.session.summaryText = ""; this.session.summaryText = "";
this.lastGlobalProgressBytes = 0; this.lastGlobalProgressBytes = 0;
this.lastGlobalProgressAt = nowMs(); this.lastGlobalProgressAt = now;
this.speedEvents = []; this.speedEvents = [];
this.speedEventsHead = 0; this.speedEventsHead = 0;
this.speedBytesLastWindow = 0; this.speedBytesLastWindow = 0;

View File

@ -6978,6 +6978,35 @@ describe("download manager", () => {
expect(savedSettings.totalRuntimeAllTimeMs || 0).toBeGreaterThanOrEqual(2 * 60 * 60 * 1000 + 100); expect(savedSettings.totalRuntimeAllTimeMs || 0).toBeGreaterThanOrEqual(2 * 60 * 60 * 1000 + 100);
}, 10000); }, 10000);
it("resets session runtime without affecting all-time runtime", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-"));
tempDirs.push(root);
const manager = new DownloadManager(
{
...defaultSettings(),
token: "rd-token",
outputDir: path.join(root, "downloads"),
extractDir: path.join(root, "extract"),
totalRuntimeAllTimeMs: 90 * 60 * 1000
},
emptySession(),
createStoragePaths(path.join(root, "state"))
);
await new Promise((resolve) => setTimeout(resolve, 120));
const beforeReset = manager.getStats();
expect(beforeReset.sessionRuntimeMs).toBeGreaterThanOrEqual(100);
manager.resetSessionStats();
const afterReset = manager.getStats();
expect(afterReset.sessionRuntimeMs).toBeLessThan(beforeReset.sessionRuntimeMs);
expect(afterReset.sessionRuntimeMs).toBeLessThan(100);
expect(afterReset.totalRuntimeMs).toBeGreaterThanOrEqual(90 * 60 * 1000);
}, 10000);
it("writes auto-rename details into rename and item logs", async () => { it("writes auto-rename details into rename and item logs", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-")); const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-"));
tempDirs.push(root); tempDirs.push(root);