fix(album): keep cover uploads out of Recently Added ordering

Cover upload/delete bumped album.updated_at to bust the artwork cache, but
recentlyAddedSort() and Subsonic albumCreatedAt() sort on updated_at when
RecentlyAddedByModTime is enabled, so a cover edit reordered Recently Added
and shifted the reported creation date.

Add a dedicated cover_art_updated_at column that UpdateImage bumps instead of
updated_at; the album artwork id, reader cache key, and UI cover URL fold it
into their cache-busting, so covers refresh everywhere while updated_at (and
Recently Added) stays untouched.

Also preserve uploaded_image across the phase-2 moved-track album-id change,
which previously copied only created_at.
This commit is contained in:
Deluan 2026-07-17 21:08:16 -04:00
commit 319662174e
12 changed files with 116 additions and 37 deletions

View file

@ -219,12 +219,12 @@ func (r *albumRepository) UpdateExternalInfo(al *model.Album) error {
return err
}
// UpdateImage is the sole writer of uploaded_image: it uses raw SQL because Put's
// structs.Map marshaling drops the structs:"-" tagged UploadedImage field.
// UpdateImage is the sole writer of uploaded_image (raw SQL: Put's structs.Map drops the
// structs:"-" field). Bumps cover_art_updated_at, not updated_at, to leave Recently Added put.
func (r *albumRepository) UpdateImage(id, filename string) error {
c, err := r.executeSQL(Update(r.tableName).
Set("uploaded_image", filename).
Set("updated_at", time.Now()).
Set("cover_art_updated_at", time.Now()).
Where(Eq{"id": id}))
if err != nil {
return err

View file

@ -70,6 +70,19 @@ var _ = Describe("AlbumRepository", func() {
It("returns ErrNotFound for a missing album", func() {
Expect(albumRepo.UpdateImage("does-not-exist", "x.jpg")).To(MatchError(model.ErrNotFound))
})
It("bumps cover_art_updated_at without touching updated_at", func() {
before, err := albumRepo.Get("img-1")
Expect(err).ToNot(HaveOccurred())
Expect(before.CoverArtUpdatedAt).To(BeNil())
Expect(albumRepo.UpdateImage("img-1", "img-1_cover.jpg")).To(Succeed())
after, err := albumRepo.Get("img-1")
Expect(err).ToNot(HaveOccurred())
Expect(after.CoverArtUpdatedAt).ToNot(BeNil())
Expect(*after.CoverArtUpdatedAt).To(BeTemporally("~", time.Now(), time.Minute))
Expect(after.UpdatedAt).To(Equal(before.UpdatedAt))
})
})
Describe("CopyAttributes", func() {