From 629dbf3ddbe2349f77fe231643484b368855c643 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Wed, 18 Mar 2026 20:07:43 +0100 Subject: [PATCH] chore: pr feedback --- .../__tests__/backups.controller.test.ts | 42 ------------------- .../modules/backups/backups.controller.ts | 5 +++ .../modules/backups/backups.execution.ts | 1 + 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/app/server/modules/backups/__tests__/backups.controller.test.ts b/app/server/modules/backups/__tests__/backups.controller.test.ts index 655945e1..17a3755c 100644 --- a/app/server/modules/backups/__tests__/backups.controller.test.ts +++ b/app/server/modules/backups/__tests__/backups.controller.test.ts @@ -4,7 +4,6 @@ import { createTestSession, getAuthHeaders } from "~/test/helpers/auth"; import { createTestVolume } from "~/test/helpers/volume"; import { createTestRepository } from "~/test/helpers/repository"; import { createTestBackupSchedule } from "~/test/helpers/backup"; -import { cache, cacheKeys } from "~/server/utils/cache"; const app = createApp(); @@ -82,47 +81,6 @@ describe("backups security", () => { }); describe("input validation", () => { - test("should return cached progress for a running backup", async () => { - const { headers, organizationId } = await createTestSession(); - const volume = await createTestVolume({ organizationId }); - const repository = await createTestRepository({ organizationId }); - const schedule = await createTestBackupSchedule({ - organizationId, - volumeId: volume.id, - repositoryId: repository.id, - }); - - cache.set(cacheKeys.backup.progress(schedule.id), { - scheduleId: schedule.shortId, - volumeName: volume.name, - repositoryName: repository.name, - message_type: "status", - seconds_elapsed: 12, - seconds_remaining: 24, - percent_done: 0.5, - total_files: 100, - files_done: 50, - total_bytes: 1024, - bytes_done: 512, - current_files: ["/mnt/data/file.txt"], - }); - - const res = await app.request(`/api/v1/backups/${schedule.shortId}/progress`, { - headers, - }); - - expect(res.status).toBe(200); - const body = await res.json(); - expect(body).toMatchObject({ - scheduleId: schedule.shortId, - percent_done: 0.5, - files_done: 50, - current_files: ["/mnt/data/file.txt"], - }); - - cache.del(cacheKeys.backup.progress(schedule.id)); - }); - test("should return a schedule when queried by short id", async () => { const { headers, organizationId } = await createTestSession(); const volume = await createTestVolume({ organizationId }); diff --git a/app/server/modules/backups/backups.controller.ts b/app/server/modules/backups/backups.controller.ts index 2b349ba0..41c54352 100644 --- a/app/server/modules/backups/backups.controller.ts +++ b/app/server/modules/backups/backups.controller.ts @@ -47,6 +47,7 @@ import { requireAuth } from "../auth/auth.middleware"; import { backupsExecutionService } from "./backups.execution"; import { logger } from "@zerobyte/core/node"; import { asShortId } from "~/server/utils/branded"; +import { cache, cacheKeys } from "~/server/utils/cache"; export const backupScheduleController = new Hono() .use(requireAuth) @@ -167,6 +168,10 @@ export const backupScheduleController = new Hono() .get("/:shortId/progress", getBackupProgressDto, async (c) => { const shortId = asShortId(c.req.param("shortId")); const schedule = await backupsService.getScheduleByShortId(shortId); + if (schedule.lastBackupStatus !== "in_progress") { + cache.del(cacheKeys.backup.progress(schedule.id)); + return c.json(null, 200); + } const progress = backupsExecutionService.getBackupProgress(schedule.id); return c.json(progress ?? null, 200); diff --git a/app/server/modules/backups/backups.execution.ts b/app/server/modules/backups/backups.execution.ts index 91a6cdca..11a8ba4e 100644 --- a/app/server/modules/backups/backups.execution.ts +++ b/app/server/modules/backups/backups.execution.ts @@ -268,6 +268,7 @@ const executeBackup = async (scheduleId: number, manual = false): Promise } const { context: ctx } = result; + cache.del(cacheKeys.backup.progress(scheduleId)); emitBackupStarted(ctx, scheduleId); const nextBackupAt = calculateNextRun(ctx.schedule.cronExpression);