From 79870b1090bb70fd449c8aee3d837b3fa0804c36 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Fri, 17 Nov 2023 00:20:37 +0000 Subject: [PATCH] Do not empty old artist metadata (#2423) --- model/artist.go | 2 +- persistence/artist_repository.go | 4 ++-- scanner/refresher.go | 3 ++- tests/mock_artist_repo.go | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/model/artist.go b/model/artist.go index 1a3ba496..f6bb33f4 100644 --- a/model/artist.go +++ b/model/artist.go @@ -49,7 +49,7 @@ type ArtistIndexes []ArtistIndex type ArtistRepository interface { CountAll(options ...QueryOptions) (int64, error) Exists(id string) (bool, error) - Put(m *Artist) error + Put(m *Artist, colsToUpdate ...string) error Get(id string) (*Artist, error) GetAll(options ...QueryOptions) (Artists, error) Search(q string, offset int, size int) (Artists, error) diff --git a/persistence/artist_repository.go b/persistence/artist_repository.go index bd3a506b..e4a0a0f7 100644 --- a/persistence/artist_repository.go +++ b/persistence/artist_repository.go @@ -60,10 +60,10 @@ func (r *artistRepository) Exists(id string) (bool, error) { return r.exists(Select().Where(Eq{"artist.id": id})) } -func (r *artistRepository) Put(a *model.Artist) error { +func (r *artistRepository) Put(a *model.Artist, colsToUpdate ...string) error { a.FullText = getFullText(a.Name, a.SortArtistName) dba := r.fromModel(a) - _, err := r.put(dba.ID, dba) + _, err := r.put(dba.ID, dba, colsToUpdate...) if err != nil { return err } diff --git a/scanner/refresher.go b/scanner/refresher.go index 2d8a8da5..ec17fc1e 100644 --- a/scanner/refresher.go +++ b/scanner/refresher.go @@ -142,7 +142,8 @@ func (r *refresher) refreshArtists(ctx context.Context, ids ...string) error { // Force a external metadata lookup on next access a.ExternalInfoUpdatedAt = time.Time{} - err := repo.Put(&a) + // 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 } diff --git a/tests/mock_artist_repo.go b/tests/mock_artist_repo.go index 6f30679f..aa0a83f3 100644 --- a/tests/mock_artist_repo.go +++ b/tests/mock_artist_repo.go @@ -50,7 +50,7 @@ func (m *MockArtistRepo) Get(id string) (*model.Artist, error) { return nil, model.ErrNotFound } -func (m *MockArtistRepo) Put(ar *model.Artist) error { +func (m *MockArtistRepo) Put(ar *model.Artist, columsToUpdate ...string) error { if m.err { return errors.New("error") }