diff --git a/docker/frontend/src/engine/library.ts b/docker/frontend/src/engine/library.ts index 60cbc3a..713e9cb 100644 --- a/docker/frontend/src/engine/library.ts +++ b/docker/frontend/src/engine/library.ts @@ -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 { +// 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 { 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 { } } +export function putPhotoThumb(id: string, blob: Blob): Promise { + return writeThumb(id, blob, true); +} + export async function getPhotoThumbs(ids: string[]): Promise> { const res = new Map(); const missing: string[] = []; @@ -1969,7 +1982,7 @@ const inFlight = new Map>(); // later visit reads the tile back instead of the file. async function tileOf(id: string, preview: Blob): Promise { 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 { // 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 {