fix(library): stop the shelf from hearing about the tiles it asked for itself

This commit is contained in:
locpham
2026-10-09 22:54:58 +07:00
parent 102dc13351
commit e03fed60f9
+17 -4
View File
@@ -1855,9 +1855,18 @@ export function onThumbWritten(listener: (id: string, blob: Blob) => void): () =
// A tile made because someone looked at the frame, kept where the next visit
// will find it: the decode is paid once per frame, on the visit that first drew
// it, and the reads after that are the same reads a scanned tile would have had.
export async function putPhotoThumb(id: string, blob: Blob): Promise<void> {
// The tile is in hand either way; `tell` is whether anyone has to hear about it.
//
// The store writes this module makes for itself — the walk's previews, and the
// tiles `makeThumb` mints for the shelf — are the shelf's own: it asked for that
// tile and is about to draw it. Telling it about those is a stamp per tile, and a
// stamp re-reads the window, and a re-read is the read in flight cancelled — on a
// roll of thousands the tiles then never land at all, which is a shelf that stays
// grey. Only a rewrite from somewhere else (the studio grading the frame the reader
// is standing on) is worth the telling.
async function writeThumb(id: string, blob: Blob, tell: boolean): Promise<void> {
cacheThumb(id, blob);
for (const listener of thumbListeners) listener(id, blob);
if (tell) for (const listener of thumbListeners) listener(id, blob);
try {
const db = await openDb();
if (!db.objectStoreNames.contains(THUMBS)) return;
@@ -1868,6 +1877,10 @@ export async function putPhotoThumb(id: string, blob: Blob): Promise<void> {
}
}
export function putPhotoThumb(id: string, blob: Blob): Promise<void> {
return writeThumb(id, blob, true);
}
export async function getPhotoThumbs(ids: string[]): Promise<Map<string, Blob>> {
const res = new Map<string, Blob>();
const missing: string[] = [];
@@ -1969,7 +1982,7 @@ const inFlight = new Map<string, Promise<Blob | null>>();
// later visit reads the tile back instead of the file.
async function tileOf(id: string, preview: Blob): Promise<Blob> {
const made = (await makeTile(preview)) ?? preview;
void putPhotoThumb(id, made);
void writeThumb(id, made, false);
return made;
}
@@ -2013,7 +2026,7 @@ async function makeOneThumb(photo: LibraryPhoto): Promise<Blob | null> {
// is drawn as it is rather than written to the store whole.
const made = await makeTile(file);
blob = made ?? file;
if (made) await putPhotoThumb(photo.id, made);
if (made) await writeThumb(photo.id, made, false);
}
return blob;
} catch {