mirror of
https://github.com/navidrome/navidrome.git
synced 2025-07-14 07:31:28 +03:00
* fix: ensure full scan refreshes all artist stats After PR #4059, full scans were not forcing a refresh of all artists. This change ensures that during full scans, all artist stats are refreshed instead of only those with recently updated media files. Changes: - Set changesDetected=true at start of full scans to ensure maintenance operations run - Add allArtists parameter to RefreshStats() method - Pass fullScan state to RefreshStats to control refresh scope - Update mock repository to match new interface Fixes #4246 Related to PR #4059 * fix: add tests for full and incremental scans Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
112 lines
2.3 KiB
Go
112 lines
2.3 KiB
Go
package tests
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/id"
|
|
)
|
|
|
|
func CreateMockArtistRepo() *MockArtistRepo {
|
|
return &MockArtistRepo{
|
|
Data: make(map[string]*model.Artist),
|
|
}
|
|
}
|
|
|
|
type MockArtistRepo struct {
|
|
model.ArtistRepository
|
|
Data map[string]*model.Artist
|
|
Err bool
|
|
}
|
|
|
|
func (m *MockArtistRepo) SetError(err bool) {
|
|
m.Err = err
|
|
}
|
|
|
|
func (m *MockArtistRepo) SetData(artists model.Artists) {
|
|
m.Data = make(map[string]*model.Artist)
|
|
for i, a := range artists {
|
|
m.Data[a.ID] = &artists[i]
|
|
}
|
|
}
|
|
|
|
func (m *MockArtistRepo) Exists(id string) (bool, error) {
|
|
if m.Err {
|
|
return false, errors.New("Error!")
|
|
}
|
|
_, found := m.Data[id]
|
|
return found, nil
|
|
}
|
|
|
|
func (m *MockArtistRepo) Get(id string) (*model.Artist, error) {
|
|
if m.Err {
|
|
return nil, errors.New("Error!")
|
|
}
|
|
if d, ok := m.Data[id]; ok {
|
|
return d, nil
|
|
}
|
|
return nil, model.ErrNotFound
|
|
}
|
|
|
|
func (m *MockArtistRepo) Put(ar *model.Artist, columsToUpdate ...string) error {
|
|
if m.Err {
|
|
return errors.New("error")
|
|
}
|
|
if ar.ID == "" {
|
|
ar.ID = id.NewRandom()
|
|
}
|
|
m.Data[ar.ID] = ar
|
|
return nil
|
|
}
|
|
|
|
func (m *MockArtistRepo) IncPlayCount(id string, timestamp time.Time) error {
|
|
if m.Err {
|
|
return errors.New("error")
|
|
}
|
|
if d, ok := m.Data[id]; ok {
|
|
d.PlayCount++
|
|
d.PlayDate = ×tamp
|
|
return nil
|
|
}
|
|
return model.ErrNotFound
|
|
}
|
|
|
|
func (m *MockArtistRepo) GetAll(options ...model.QueryOptions) (model.Artists, error) {
|
|
if m.Err {
|
|
return nil, errors.New("mock repo error")
|
|
}
|
|
var allArtists model.Artists
|
|
for _, artist := range m.Data {
|
|
allArtists = append(allArtists, *artist)
|
|
}
|
|
// Apply Max=1 if present (simple simulation for findArtistByName)
|
|
if len(options) > 0 && options[0].Max == 1 && len(allArtists) > 0 {
|
|
return allArtists[:1], nil
|
|
}
|
|
return allArtists, nil
|
|
}
|
|
|
|
func (m *MockArtistRepo) UpdateExternalInfo(artist *model.Artist) error {
|
|
if m.Err {
|
|
return errors.New("mock repo error")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockArtistRepo) RefreshStats(allArtists bool) (int64, error) {
|
|
if m.Err {
|
|
return 0, errors.New("mock repo error")
|
|
}
|
|
return int64(len(m.Data)), nil
|
|
}
|
|
|
|
func (m *MockArtistRepo) RefreshPlayCounts() (int64, error) {
|
|
if m.Err {
|
|
return 0, errors.New("mock repo error")
|
|
}
|
|
return int64(len(m.Data)), nil
|
|
}
|
|
|
|
var _ model.ArtistRepository = (*MockArtistRepo)(nil)
|