Rebuild the enrichment cache when its pictures were swept

The nightly photo sweep deletes every candidate nobody picked, which is most of
them. The cached result still pointed at those files, and the read filtered them
out - so the morning after, a place with perfectly available pictures showed an
empty column, and kept showing one for the rest of the week the entry lives.

A missing candidate now invalidates the whole entry instead of shrinking it.
This commit is contained in:
Maurice
2026-08-09 23:04:08 +02:00
committed by Maurice
parent 1f1ed630fc
commit fc9ac64496
2 changed files with 36 additions and 7 deletions
@@ -300,10 +300,13 @@ export class PlaceEnrichmentService {
if (!row || Date.now() - row.fetched_at >= CACHE_TTL_MS) return null;
const parsed = JSON.parse(row.payload_json) as CachedEnrichment;
// A cached candidate is only usable while its bytes are still on disk —
// the nightly sweep removes pictures nobody picked, and serving their
// proxy URLs afterwards would fill the strip with broken images.
// A cached candidate is only usable while its bytes are still on disk, and
// the nightly sweep deletes every picture nobody picked — which is most of
// them. Treat any loss as a stale entry and rebuild, rather than serving
// the survivors: filtering alone would leave the column empty for the rest
// of the week for a place that has pictures perfectly available.
const photos = parsed.photos.filter((photo) => this.photoCache.get(photo.key));
if (photos.length !== parsed.photos.length) return null;
return { photos, description: parsed.description ?? null };
} catch {
return null;