diff --git a/web/src/lib/services/bulk.ts b/web/src/lib/services/bulk.ts index 9b7612f..15177d4 100644 --- a/web/src/lib/services/bulk.ts +++ b/web/src/lib/services/bulk.ts @@ -33,27 +33,33 @@ export function invalidatePhotos(uids: string[]): void { } /** - * Remove uids from every cached photo-list page so the grid updates - * instantly instead of waiting for a refetch round-trip. Call after the - * API confirms the mutation, then still invalidate for eventual sync. + * Remove uids from every cached infinite photo-list query so the grid + * updates instantly instead of waiting for a refetch round-trip. Call + * after the API confirms the mutation, then still invalidate for eventual + * sync. Only targets infinite queries (those with a `pages` array) — + * flat list caches like marks-pool, with-notes, keywords, etc. are left + * intact so tag/category drill pages don't lose referenced photos. */ export function evictFromCache(uids: string[]): void { const uidSet = new Set(uids); - const lists = queryClient.getQueriesData({ + const lists = queryClient.getQueriesData< + { pages?: PpPhoto[][] } | { pages?: unknown[] } + >({ queryKey: ['photos'] }); for (const [key, data] of lists) { if (!data) continue; - if (Array.isArray(data)) { - const filtered = data.filter((p) => !uidSet.has(p.UID)); - if (filtered.length < data.length) { - queryClient.setQueryData(key, filtered); + if ('pages' in data && Array.isArray((data as { pages?: unknown[] }).pages)) { + const pages = (data as { pages: PpPhoto[][] }).pages; + let changed = false; + const filtered = pages.map((page: PpPhoto[]) => { + const f = page.filter((p) => !uidSet.has(p.UID)); + if (f.length < page.length) changed = true; + return f; + }); + if (changed) { + queryClient.setQueryData(key, { ...data, pages: filtered }); } - } else if (data && 'pages' in data && Array.isArray(data.pages)) { - const pages = data.pages.map((page: PpPhoto[]) => - page.filter((p) => !uidSet.has(p.UID)) - ); - queryClient.setQueryData(key, { ...data, pages }); } } }