From a1cc89c66e01e64a0ee562237cc26ebe4867b4a1 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Tue, 11 Nov 2025 18:01:54 +0100 Subject: [PATCH] fix: ensure caching in file explorers --- apps/client/app/components/directory-browser.tsx | 2 +- apps/client/app/components/volume-file-browser.tsx | 4 ++-- .../modules/backups/components/snapshot-file-browser.tsx | 8 ++++---- .../src/modules/repositories/repositories.controller.ts | 4 +--- apps/server/src/modules/volumes/volume.controller.ts | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/client/app/components/directory-browser.tsx b/apps/client/app/components/directory-browser.tsx index f8ce40e..29650f9 100644 --- a/apps/client/app/components/directory-browser.tsx +++ b/apps/client/app/components/directory-browser.tsx @@ -46,7 +46,7 @@ export const DirectoryBrowser = ({ onSelectPath, selectedPath }: Props) => { setLoadingFolders((prev) => new Set(prev).add(folderPath)); try { - const result = await queryClient.fetchQuery( + const result = await queryClient.ensureQueryData( browseFilesystemOptions({ query: { path: folderPath }, }), diff --git a/apps/client/app/components/volume-file-browser.tsx b/apps/client/app/components/volume-file-browser.tsx index 1873fff..75ac4e9 100644 --- a/apps/client/app/components/volume-file-browser.tsx +++ b/apps/client/app/components/volume-file-browser.tsx @@ -72,7 +72,7 @@ export const VolumeFileBrowser = ({ setLoadingFolders((prev) => new Set(prev).add(folderPath)); try { - const result = await queryClient.fetchQuery( + const result = await queryClient.ensureQueryData( listFilesOptions({ path: { name: volumeName }, query: { path: folderPath }, @@ -101,7 +101,7 @@ export const VolumeFileBrowser = ({ } } }, - [volumeName, fetchedFolders, queryClient.fetchQuery], + [volumeName, fetchedFolders, queryClient.ensureQueryData], ); const handleFolderHover = useCallback( diff --git a/apps/client/app/modules/backups/components/snapshot-file-browser.tsx b/apps/client/app/modules/backups/components/snapshot-file-browser.tsx index 672ac6e..2eb273e 100644 --- a/apps/client/app/modules/backups/components/snapshot-file-browser.tsx +++ b/apps/client/app/modules/backups/components/snapshot-file-browser.tsx @@ -104,7 +104,7 @@ export const SnapshotFileBrowser = (props: Props) => { try { const fullPath = addBasePath(folderPath); - const result = await queryClient.fetchQuery( + const result = await queryClient.ensureQueryData( listSnapshotFilesOptions({ path: { name: repositoryName, snapshotId: snapshot.short_id }, query: { path: fullPath }, @@ -145,12 +145,12 @@ export const SnapshotFileBrowser = (props: Props) => { if (!fetchedFolders.has(folderPath) && !loadingFolders.has(folderPath)) { const fullPath = addBasePath(folderPath); - queryClient.prefetchQuery( - listSnapshotFilesOptions({ + queryClient.prefetchQuery({ + ...listSnapshotFilesOptions({ path: { name: repositoryName, snapshotId: snapshot.short_id }, query: { path: fullPath }, }), - ); + }); } }, [repositoryName, snapshot, fetchedFolders, loadingFolders, queryClient, addBasePath], diff --git a/apps/server/src/modules/repositories/repositories.controller.ts b/apps/server/src/modules/repositories/repositories.controller.ts index ac7b495..36eee2c 100644 --- a/apps/server/src/modules/repositories/repositories.controller.ts +++ b/apps/server/src/modules/repositories/repositories.controller.ts @@ -73,8 +73,6 @@ export const repositoriesController = new Hono() }; }); - // c.header("Cache-Control", "public, max-age=10, stale-while-revalidate=60"); - return c.json(snapshots, 200); }) .get("/:name/snapshots/:snapshotId", getSnapshotDetailsDto, async (c) => { @@ -108,7 +106,7 @@ export const repositoriesController = new Hono() const result = await repositoriesService.listSnapshotFiles(name, snapshotId, path); - // c.header("Cache-Control", "max-age=300, stale-while-revalidate=600"); + c.header("Cache-Control", "max-age=300, stale-while-revalidate=600"); return c.json(result, 200); }, diff --git a/apps/server/src/modules/volumes/volume.controller.ts b/apps/server/src/modules/volumes/volume.controller.ts index 2087797..94c0818 100644 --- a/apps/server/src/modules/volumes/volume.controller.ts +++ b/apps/server/src/modules/volumes/volume.controller.ts @@ -120,7 +120,7 @@ export const volumeController = new Hono() path: result.path, }; - // c.header("Cache-Control", "public, max-age=10, stale-while-revalidate=60"); + c.header("Cache-Control", "public, max-age=10, stale-while-revalidate=60"); return c.json(response, 200); })