From 50c90e8ee391728e32915210d2a3aa46afbd1a05 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 8 Nov 2023 23:05:16 +0000 Subject: [PATCH] set a temporary album tag artist for those who mightn't have it yet --- db/migrations.go | 15 +++++++++++++++ server/ctrlsubsonic/handlers_common.go | 22 +--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/db/migrations.go b/db/migrations.go index 0259998..401d4ae 100644 --- a/db/migrations.go +++ b/db/migrations.go @@ -70,6 +70,7 @@ func (db *DB) Migrate(ctx MigrationContext) error { construct(ctx, "202310281803", migrateTrackArtists), construct(ctx, "202311062259", migrateArtistAppearances), construct(ctx, "202311072309", migrateAlbumInfo), + construct(ctx, "202311082304", migrateTemporaryDisplayAlbumArtist), } return gormigrate. @@ -787,3 +788,17 @@ func migrateAlbumInfo(tx *gorm.DB, _ MigrationContext) error { ). Error } + +func migrateTemporaryDisplayAlbumArtist(tx *gorm.DB, _ MigrationContext) error { + // keep some things working so that people have an album.tag_artist_id until their next full scan + return tx.Exec(` + UPDATE albums + SET tag_album_artist=( + SELECT group_concat(artists.name, ', ') + FROM artists + JOIN album_artists ON album_artists.artist_id=artists.id AND album_artists.album_id=albums.id + GROUP BY album_artists.album_id + ) + WHERE tag_album_artist='' + `).Error +} diff --git a/server/ctrlsubsonic/handlers_common.go b/server/ctrlsubsonic/handlers_common.go index b435f53..ec5c4f3 100644 --- a/server/ctrlsubsonic/handlers_common.go +++ b/server/ctrlsubsonic/handlers_common.go @@ -7,8 +7,6 @@ import ( "math" "net/http" "path/filepath" - "sort" - "strings" "sync" "time" "unicode" @@ -72,7 +70,7 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response { scrobbleTrack.Track = track.TagTitle scrobbleTrack.Artist = track.TagTrackArtist scrobbleTrack.Album = track.Album.TagTitle - scrobbleTrack.AlbumArtist = albumArtistString(track.Album) + scrobbleTrack.AlbumArtist = track.Album.TagAlbumArtist scrobbleTrack.TrackNumber = uint(track.TagTrackNumber) scrobbleTrack.Duration = time.Second * time.Duration(track.Length) if _, err := uuid.Parse(track.TagBrainzID); err == nil { @@ -517,21 +515,3 @@ func lowerUDecOrHash(in string) string { } return string(lower) } - -// not everyone's records may have the album.TagAlbumArtist column set, since we didn't always store that. -// try it first, but fallback to a list from the artists table -func albumArtistString(album *db.Album) string { - if album.TagAlbumArtist != "" { - return album.TagAlbumArtist - } - - artists := append([]*db.Artist(nil), album.Artists...) - sort.Slice(artists, func(i, j int) bool { - return artists[i].ID < artists[j].ID - }) - names := make([]string, 0, len(artists)) - for _, artist := range artists { - names = append(names, artist.Name) - } - return strings.Join(names, ", ") -}