Associate main entities with library

This commit is contained in:
Deluan
2024-05-07 17:52:13 +02:00
committed by Deluan Quintão
parent 477bcaee58
commit 478c709a64
14 changed files with 153 additions and 135 deletions
+13 -4
View File
@@ -12,7 +12,6 @@ import (
"github.com/navidrome/navidrome/core/artwork"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
. "github.com/navidrome/navidrome/utils/gg"
"github.com/navidrome/navidrome/utils/slice"
"golang.org/x/exp/maps"
)
@@ -24,15 +23,17 @@ import (
// The actual mappings happen in MediaFiles.ToAlbum() and Albums.ToAlbumArtist()
type refresher struct {
ds model.DataStore
lib model.Library
album map[string]struct{}
artist map[string]struct{}
dirMap dirMap
cacheWarmer artwork.CacheWarmer
}
func newRefresher(ds model.DataStore, cw artwork.CacheWarmer, dirMap dirMap) *refresher {
func newRefresher(ds model.DataStore, cw artwork.CacheWarmer, lib model.Library, dirMap dirMap) *refresher {
return &refresher{
ds: ds,
lib: lib,
album: map[string]struct{}{},
artist: map[string]struct{}{},
dirMap: dirMap,
@@ -101,6 +102,7 @@ func (r *refresher) refreshAlbums(ctx context.Context, ids ...string) error {
if updatedAt.After(a.UpdatedAt) {
a.UpdatedAt = updatedAt
}
a.LibraryID = r.lib.ID
err := repo.Put(&a)
if err != nil {
return err
@@ -135,18 +137,25 @@ func (r *refresher) refreshArtists(ctx context.Context, ids ...string) error {
}
repo := r.ds.Artist(ctx)
libRepo := r.ds.Library(ctx)
grouped := slice.Group(albums, func(al model.Album) string { return al.AlbumArtistID })
for _, group := range grouped {
a := model.Albums(group).ToAlbumArtist()
// Force a external metadata lookup on next access
a.ExternalInfoUpdatedAt = P(time.Time{})
// Force an external metadata lookup on next access
a.ExternalInfoUpdatedAt = &time.Time{}
// Do not remove old metadata
err := repo.Put(&a, "album_count", "genres", "external_info_updated_at", "mbz_artist_id", "name", "order_artist_name", "size", "sort_artist_name", "song_count")
if err != nil {
return err
}
// Link the artist to the current library being scanned
err = libRepo.AddArtist(r.lib.ID, a.ID)
if err != nil {
return err
}
r.cacheWarmer.PreCache(a.CoverArtID())
}
return nil