fix(scanner): ensure full scans update the DB (#4252)

* 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>
This commit is contained in:
Deluan Quintão
2025-06-23 13:26:48 -04:00
committed by GitHub
parent 1bec99a2f8
commit e5e2d860ef
5 changed files with 106 additions and 12 deletions
+14 -3
View File
@@ -45,14 +45,25 @@ func (s *scanState) sendError(err error) {
}
func (s *scannerImpl) scanAll(ctx context.Context, fullScan bool, progress chan<- *ProgressInfo) {
state := scanState{progress: progress, fullScan: fullScan}
startTime := time.Now()
state := scanState{
progress: progress,
fullScan: fullScan,
changesDetected: atomic.Bool{},
}
// Set changesDetected to true for full scans to ensure all maintenance operations run
if fullScan {
state.changesDetected.Store(true)
}
libs, err := s.ds.Library(ctx).GetAll()
if err != nil {
state.sendWarning(fmt.Sprintf("getting libraries: %s", err))
return
}
startTime := time.Now()
log.Info(ctx, "Scanner: Starting scan", "fullScan", state.fullScan, "numLibraries", len(libs))
// Store scan type and start time
@@ -148,7 +159,7 @@ func (s *scannerImpl) runRefreshStats(ctx context.Context, state *scanState) fun
return nil
}
start := time.Now()
stats, err := s.ds.Artist(ctx).RefreshStats()
stats, err := s.ds.Artist(ctx).RefreshStats(state.fullScan)
if err != nil {
log.Error(ctx, "Scanner: Error refreshing artists stats", err)
return fmt.Errorf("refreshing artists stats: %w", err)