perf: evict archived/deleted photos from cache immediately
Remove archived/restored/deleted/approved UIDs from all cached photo-list pages right after the API confirms, so the grid updates on the same tick instead of waiting for a network round-trip. Also removes the 400ms doneBulk animation delay (now unnecessary since tiles vanish instantly).
This commit is contained in:
@@ -32,6 +32,32 @@ 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.
|
||||
*/
|
||||
export function evictFromCache(uids: string[]): void {
|
||||
const uidSet = new Set(uids);
|
||||
const lists = queryClient.getQueriesData<PpPhoto[] | { pages?: PpPhoto[][] }>({
|
||||
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);
|
||||
}
|
||||
} 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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a patch to every uid. The patch can be a static body or a per-photo
|
||||
* function (used by keyword merges which need to read each photo's current
|
||||
|
||||
Reference in New Issue
Block a user