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

@ -450,7 +450,7 @@ func (p *phaseFolders) persistAlbum(repo model.AlbumRepository, a *model.Album,
}
// Keep created_at and any uploaded cover from the previous instance of the album
if err := repo.CopyAttributes(prevID, a.ID, "created_at", "uploaded_image"); err != nil {
if err := repo.CopyAttributes(prevID, a.ID, "created_at", "uploaded_image", "cover_art_updated_at"); err != nil {
// Silently ignore when the previous album is not found
if !errors.Is(err, model.ErrNotFound) {
log.Warn(p.ctx, "Scanner: Could not copy fields", "from", prevID, "to", a.ID, "album", a.Name, err)

View file

@ -313,11 +313,11 @@ func (p *phaseMissingTracks) moveMatched(target, missing model.MediaFile) error
log.Warn(p.ctx, "Scanner: Could not reassign album annotations", "from", oldAlbumID, "to", newAlbumID, err)
}
// Keep created_at field from previous instance of the album, so moved albums
// don't appear in "Recently Added"
if err := tx.Album(p.ctx).CopyAttributes(oldAlbumID, newAlbumID, "created_at"); err != nil {
// Keep created_at (so moved albums don't resurface in "Recently Added")
// and any manually uploaded cover from the previous album instance.
if err := tx.Album(p.ctx).CopyAttributes(oldAlbumID, newAlbumID, "created_at", "uploaded_image", "cover_art_updated_at"); err != nil {
if !errors.Is(err, model.ErrNotFound) {
log.Warn(p.ctx, "Scanner: Could not copy album created_at", "from", oldAlbumID, "to", newAlbumID, err)
log.Warn(p.ctx, "Scanner: Could not copy album attributes", "from", oldAlbumID, "to", newAlbumID, err)
}
}

View file

@ -841,6 +841,31 @@ var _ = Describe("phaseMissingTracks", func() {
Expect(newAlbum.CreatedAt).To(Equal(originalTime))
})
It("should preserve an uploaded cover during moves with album change", func() {
missingTrack := model.MediaFile{
ID: "missing-img", PID: "C", Path: "lib1/song.mp3",
AlbumID: "old-album", LibraryID: 1,
}
matchedTrack := model.MediaFile{
ID: "matched-img", PID: "C", Path: "lib2/song.mp3",
AlbumID: "new-album", LibraryID: 2,
}
albumRepo.SetData(model.Albums{
{ID: "old-album", LibraryID: 1, UploadedImage: "old-album_cover.jpg"},
{ID: "new-album", LibraryID: 2},
})
_ = ds.MediaFile(ctx).Put(&missingTrack)
_ = ds.MediaFile(ctx).Put(&matchedTrack)
Expect(phase.moveMatched(matchedTrack, missingTrack)).To(Succeed())
newAlbum, err := albumRepo.Get("new-album")
Expect(err).ToNot(HaveOccurred())
Expect(newAlbum.UploadedImage).To(Equal("old-album_cover.jpg"))
})
It("should not copy album created_at when album ID does not change", func() {
originalTime := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
missingTrack := model.MediaFile{