fix(artwork): clear the stored hash when a recompute yields no result

A cover deleted or corrupted in place (mtime-only signal, row unchanged)
left the old blur_hash in the DB, and the DTO kept emitting a hash for
artwork no longer served. Since the worker only reaches compute when there
is change evidence, a no-result with a stored hash now clears it, making
the DTO fall back to the rotating fake.
This commit is contained in:
Deluan 2026-07-17 12:48:36 -04:00
parent 3a8505584b
commit c4ca3dca5e
2 changed files with 22 additions and 0 deletions

View File

@ -183,6 +183,13 @@ func (u *blurHashUpdater) process(ctx context.Context, artID model.ArtworkID, re
// with a TTL: browsing stays cheap, and failures still retry once it expires.
log.Trace(ctx, "BlurHash: nothing to persist", "artID", artID, err)
u.setNoResult(artID, sig)
// Reaching compute with a stored hash means there was change evidence — clear it, so the
// DTO falls back to the rotating fake instead of describing artwork no longer served.
if stored != "" {
if err := u.persist(ctx, artID, "", sig); err != nil {
log.Warn(ctx, "BlurHash: error clearing stale hash", "artID", artID, err)
}
}
return
}
if err := u.persist(ctx, artID, hash, sig); err != nil {

View File

@ -101,6 +101,21 @@ var _ = Describe("blurHashUpdater", func() {
Expect(last.sig).To(Equal(newer))
})
It("clears a stored hash when a recompute with change evidence yields no result", func() {
storedAt := version.Add(-time.Hour)
al := model.Album{ID: "al-1", UpdatedAt: version, BlurHash: "LEHV6nWB2yk8", BlurHashUpdatedAt: &storedAt}
repo := tests.CreateMockAlbumRepo()
repo.SetData(model.Albums{al})
ds.MockedAlbum = repo
ds.MockedFolder = failingFolderRepo{}
// storedAt < version = change evidence; the compute fails, so the stale hash must go.
u.process(GinkgoT().Context(), al.CoverArtID(), enqueueRequest{imageUpdatedAt: version})
stored, err := ds.Album(GinkgoT().Context()).Get("al-1")
Expect(err).ToNot(HaveOccurred())
Expect(stored.BlurHash).To(BeEmpty())
})
It("does nothing when the entity is gone", func() {
ds.MockedAlbum = tests.CreateMockAlbumRepo()
Expect(func() {