fix(jellyfin): fold folder image mtimes into the album blurhash version

An in-place cover-file swap followed by a quick scan updates only the folder's
images_updated_at: no tracks are imported, so the album row never moves and
ArtworkUpdatedAt() stayed at the old value. The Jellyfin DTO then kept emitting
the previous stored blurhash, and clients that key their cover caches on it never
refetched the image, so the served-bytes recompute could never run.

The album select now surfaces the newest folder images_updated_at (bare-column
correlated subquery over json_each(folder_ids), so the datetime decltype survives
and scans as time.Time) and ArtworkUpdatedAt() folds it in. Benchmarked on a 96K
track production copy: ~90us/page added, no query-plan change; the subquery is a
PK point lookup per folder with at most two rows to order. Artist images and
playlist sidecars have the same theoretical gap but their timestamps cannot be
derived in SQL; they remain a documented follow-up.
This commit is contained in:
Deluan 2026-07-17 22:14:13 -04:00
commit 07af29fbb4
6 changed files with 104 additions and 2 deletions

View file

@ -72,6 +72,10 @@ type Album struct {
// full-row writes (structs:"-"): only UpdateBlurHash writes it, so scans can't erase it.
BlurHash string `structs:"-" json:"blurHash,omitempty" hash:"ignore"`
BlurHashUpdatedAt *time.Time `structs:"-" json:"-" hash:"ignore"`
// FolderImagesUpdatedAt is the newest images_updated_at among the album's folders (selected, not
// persisted): an in-place cover-file swap moves it even though the album row stays untouched.
FolderImagesUpdatedAt *time.Time `structs:"-" json:"-" hash:"ignore"`
}
func (a Album) CoverArtID() ArtworkID {
@ -86,6 +90,9 @@ func (a Album) ArtworkUpdatedAt() time.Time {
if a.ImportedAt.After(t) {
t = a.ImportedAt
}
if a.FolderImagesUpdatedAt != nil && a.FolderImagesUpdatedAt.After(t) {
t = *a.FolderImagesUpdatedAt
}
return t
}

View file

@ -69,4 +69,12 @@ var _ = Describe("Album.ArtworkUpdatedAt", func() {
al := Album{UpdatedAt: base, ImportedAt: later, ExternalInfoUpdatedAt: &latest}
Expect(al.ArtworkUpdatedAt()).To(Equal(later))
})
It("returns FolderImagesUpdatedAt when it is the newest (in-place cover swap)", func() {
al := Album{UpdatedAt: base, ImportedAt: later, FolderImagesUpdatedAt: &latest}
Expect(al.ArtworkUpdatedAt()).To(Equal(latest))
})
It("ignores an older FolderImagesUpdatedAt", func() {
al := Album{UpdatedAt: later, ImportedAt: base, FolderImagesUpdatedAt: &base}
Expect(al.ArtworkUpdatedAt()).To(Equal(later))
})
})