fix(artwork): clear the stored hash when the artwork source disappears

A removed cover made Get error with ErrUnavailable before the enqueue, so
the worker never saw the entity and the stale hash kept being emitted. The
unavailable path now enqueues too; the worker's reader signal carries the
folder change and the existing no-result clearing applies. Covered by an
e2e spec exercising the full disappear-and-clear flow.
This commit is contained in:
Deluan 2026-07-17 13:33:45 -04:00
parent 0e74cf0ab1
commit a7eec3afc3
2 changed files with 33 additions and 0 deletions

View File

@ -80,6 +80,11 @@ func (a *artwork) Get(ctx context.Context, artID model.ArtworkID, size int, squa
if !errors.Is(err, context.Canceled) && !errors.Is(err, ErrUnavailable) {
log.Error(ctx, "Error accessing image cache", "id", artID, "size", size, err)
}
// A vanished source must still reach the worker, or a stored hash would keep describing
// artwork that no longer exists.
if a.blurHashes != nil && errors.Is(err, ErrUnavailable) {
a.blurHashes.Enqueue(artID, artReader.LastUpdated(), false)
}
return nil, time.Time{}, err
}
if a.blurHashes != nil {

View File

@ -35,6 +35,34 @@ var _ = Describe("BlurHash", func() {
}, "10s", "100ms").Should(Succeed())
})
It("clears the stored blurhash when the cover disappears", func() {
setLayout(fstest.MapFS{
"Artist/Album/01 - Song.mp3": trackFile(1, "Song"),
"Artist/Album/cover.png": realPNG("vanishing-cover"),
})
scan()
al := firstAlbum()
readArtwork(al.CoverArtID())
Eventually(func(g Gomega) {
updated, err := ds.Album(ctx).Get(al.ID)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(updated.BlurHash).ToNot(BeEmpty())
}, "10s", "100ms").Should(Succeed())
setLayout(fstest.MapFS{
"Artist/Album/01 - Song.mp3": trackFile(1, "Song"),
})
scan()
_, err := readArtworkOrErr(al.CoverArtID())
Expect(err).To(HaveOccurred())
Eventually(func(g Gomega) {
updated, err := ds.Album(ctx).Get(al.ID)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(updated.BlurHash).To(BeEmpty())
}, "10s", "100ms").Should(Succeed())
})
It("does not persist a blurhash when the served image cannot be decoded", func() {
setLayout(fstest.MapFS{
"Artist/Album/01 - Song.mp3": trackFile(1, "Song"),