revert evictFromCache, add back delay + marks invalidation

Remove evictFromCache entirely - the cache-manipulation approach was
brittle and broke both archive (photos not removed) and tags
(colors/ratings showing empty). Replace with: 200ms delay before
invalidation to let PhotoPrism's indexer process the change, plus
invalidateQueries(['marks']) so tag caches (colors, ratings, notes)
refresh alongside the photo timeline.
This commit is contained in:
2026-06-07 22:31:39 +02:00
parent 82f2a40269
commit 73c36b4817
5 changed files with 14 additions and 45 deletions

View File

@@ -32,36 +32,12 @@ export function invalidatePhotos(uids: string[]): void {
}
}
/**
* 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<
{ pages?: PpPhoto[][] } | { pages?: unknown[] }
>({
queryKey: ['photos']
});
for (const [key, data] of lists) {
if (!data) continue;
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 });
}
}
}
export function invalidateAllPhotoCaches(): void {
void queryClient.invalidateQueries({ queryKey: ['photos'] });
void queryClient.invalidateQueries({ queryKey: ['marks'] });
void queryClient.invalidateQueries({ queryKey: ['labels'] });
void queryClient.invalidateQueries({ queryKey: ['review-groups'] });
void queryClient.invalidateQueries({ queryKey: ['heaps'] });
}
/**