fix: various album_artists <-> artists mismatches

This commit is contained in:
Deluan
2020-03-26 09:08:53 -04:00
parent 5331732236
commit dcb3b3b5d1
7 changed files with 40 additions and 24 deletions
+2
View File
@@ -121,9 +121,11 @@ func (r *albumRepository) Refresh(ids ...string) error {
}
if al.Compilation {
al.AlbumArtist = consts.VariousArtists
al.AlbumArtistID = consts.VariousArtistsID
}
if al.AlbumArtist == "" {
al.AlbumArtist = al.Artist
al.AlbumArtistID = al.ArtistID
}
al.UpdatedAt = time.Now()
if al.CurrentId != "" {
+3 -13
View File
@@ -8,7 +8,6 @@ import (
. "github.com/Masterminds/squirrel"
"github.com/astaxie/beego/orm"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/utils"
@@ -109,13 +108,10 @@ func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) {
func (r *artistRepository) Refresh(ids ...string) error {
type refreshArtist struct {
model.Artist
CurrentId string
AlbumArtist string
Compilation bool
CurrentId string
}
var artists []refreshArtist
sel := Select("f.album_artist_id as id", "f.artist as name", "f.album_artist", "f.compilation",
"count(*) as album_count", "a.id as current_id").
sel := Select("f.album_artist_id as id", "f.album_artist as name", "count(*) as album_count", "a.id as current_id").
From("album f").
LeftJoin("artist a on f.album_artist_id = a.id").
Where(Eq{"f.album_artist_id": ids}).
@@ -128,12 +124,6 @@ func (r *artistRepository) Refresh(ids ...string) error {
toInsert := 0
toUpdate := 0
for _, ar := range artists {
if ar.Compilation {
ar.AlbumArtist = consts.VariousArtists
}
if ar.AlbumArtist != "" {
ar.Name = ar.AlbumArtist
}
if ar.CurrentId != "" {
toUpdate++
} else {
@@ -161,7 +151,7 @@ func (r *artistRepository) GetStarred(options ...model.QueryOptions) (model.Arti
}
func (r *artistRepository) PurgeEmpty() error {
del := Delete(r.tableName).Where("id not in (select distinct(artist_id) from album)")
del := Delete(r.tableName).Where("id not in (select distinct(album_artist_id) from album)")
c, err := r.executeSQL(del)
if err == nil {
if c > 0 {