fix: evictFromCache only targets infinite queries (not flat caches)
evictFromCache was removing archived UIDs from ALL ['photos']-prefixed queries, including flat lists like marks-pool and with-notes. This corrupted the tag drill pages — when navigating to Colors/Ratings after setting marks, the pool was missing photos and the grid showed empty. Now only infinite queries (those with a pages array) are filtered.
This commit is contained in:
@@ -33,27 +33,33 @@ export function invalidatePhotos(uids: string[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove uids from every cached photo-list page so the grid updates
|
* Remove uids from every cached infinite photo-list query so the grid
|
||||||
* instantly instead of waiting for a refetch round-trip. Call after the
|
* updates instantly instead of waiting for a refetch round-trip. Call
|
||||||
* API confirms the mutation, then still invalidate for eventual sync.
|
* 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 {
|
export function evictFromCache(uids: string[]): void {
|
||||||
const uidSet = new Set(uids);
|
const uidSet = new Set(uids);
|
||||||
const lists = queryClient.getQueriesData<PpPhoto[] | { pages?: PpPhoto[][] }>({
|
const lists = queryClient.getQueriesData<
|
||||||
|
{ pages?: PpPhoto[][] } | { pages?: unknown[] }
|
||||||
|
>({
|
||||||
queryKey: ['photos']
|
queryKey: ['photos']
|
||||||
});
|
});
|
||||||
for (const [key, data] of lists) {
|
for (const [key, data] of lists) {
|
||||||
if (!data) continue;
|
if (!data) continue;
|
||||||
if (Array.isArray(data)) {
|
if ('pages' in data && Array.isArray((data as { pages?: unknown[] }).pages)) {
|
||||||
const filtered = data.filter((p) => !uidSet.has(p.UID));
|
const pages = (data as { pages: PpPhoto[][] }).pages;
|
||||||
if (filtered.length < data.length) {
|
let changed = false;
|
||||||
queryClient.setQueryData(key, filtered);
|
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 });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user