fix(library): stop the shelf from hearing about the tiles it asked for itself
This commit is contained in:
@@ -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
|
// 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
|
// 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.
|
// 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);
|
cacheThumb(id, blob);
|
||||||
for (const listener of thumbListeners) listener(id, blob);
|
if (tell) for (const listener of thumbListeners) listener(id, blob);
|
||||||
try {
|
try {
|
||||||
const db = await openDb();
|
const db = await openDb();
|
||||||
if (!db.objectStoreNames.contains(THUMBS)) return;
|
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>> {
|
export async function getPhotoThumbs(ids: string[]): Promise<Map<string, Blob>> {
|
||||||
const res = new Map<string, Blob>();
|
const res = new Map<string, Blob>();
|
||||||
const missing: string[] = [];
|
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.
|
// later visit reads the tile back instead of the file.
|
||||||
async function tileOf(id: string, preview: Blob): Promise<Blob> {
|
async function tileOf(id: string, preview: Blob): Promise<Blob> {
|
||||||
const made = (await makeTile(preview)) ?? preview;
|
const made = (await makeTile(preview)) ?? preview;
|
||||||
void putPhotoThumb(id, made);
|
void writeThumb(id, made, false);
|
||||||
return made;
|
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.
|
// is drawn as it is rather than written to the store whole.
|
||||||
const made = await makeTile(file);
|
const made = await makeTile(file);
|
||||||
blob = made ?? file;
|
blob = made ?? file;
|
||||||
if (made) await putPhotoThumb(photo.id, made);
|
if (made) await writeThumb(photo.id, made, false);
|
||||||
}
|
}
|
||||||
return blob;
|
return blob;
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user