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:
@@ -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'] });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { batchEdit } from './batch';
|
||||
import { invalidatePhotos, evictFromCache } from './bulk';
|
||||
import { invalidatePhotos } from './bulk';
|
||||
import {
|
||||
approvePhoto,
|
||||
batchArchive,
|
||||
@@ -68,7 +68,6 @@ export async function dismissPhotos(uids: string[]): Promise<void> {
|
||||
if (uids.length === 0) return;
|
||||
const tid = toast.loading(`Dismissing ${uids.length}…`);
|
||||
const { updated, errors } = await batchEdit(uids, (id) => approvePhoto(id));
|
||||
evictFromCache(uids);
|
||||
focusAfter(uids);
|
||||
clearSelection();
|
||||
invalidatePhotos(uids);
|
||||
@@ -108,7 +107,6 @@ export async function acceptDateAndKeep(uids: string[]): Promise<void> {
|
||||
await approvePhoto(id);
|
||||
return id;
|
||||
});
|
||||
evictFromCache(uids);
|
||||
focusAfter(uids);
|
||||
clearSelection();
|
||||
invalidatePhotos(uids);
|
||||
@@ -135,7 +133,6 @@ export async function archivePhotos(uids: string[]): Promise<void> {
|
||||
toast.error(err instanceof Error ? err.message : 'Archive failed', { id: tid });
|
||||
return;
|
||||
}
|
||||
evictFromCache(uids);
|
||||
pushUndo(`Archived ${uids.length}`, async () => {
|
||||
await batchRestore(uids);
|
||||
invalidatePhotos(uids);
|
||||
|
||||
Reference in New Issue
Block a user