Skip to content

🎧 Your Personal Streaming Service

fix(scanner): update lib.LastScanAt on each rescan (#3313)

Deluan Quintão76614b8f1611
diff --git a/scanner/scanner.go b/scanner/scanner.go
index fbf12cf20..365ad1d57 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -35,7 +35,7 @@ var (
type FolderScanner interface {
// Scan process finds any changes after `lastModifiedSince` and returns the number of changes found
- Scan(ctx context.Context, fullRescan bool, progress chan uint32) (int64, error)
+ Scan(ctx context.Context, lib model.Library, fullRescan bool, progress chan uint32) (int64, error)
}
var isScanning sync.Mutex
@@ -98,7 +98,7 @@ func (s *scanner) rescan(ctx context.Context, library string, fullRescan bool) e
progress, cancel := s.startProgressTracker(library)
defer cancel()
- changeCount, err := folderScanner.Scan(ctx, fullRescan, progress)
+ changeCount, err := folderScanner.Scan(ctx, lib, fullRescan, progress)
if err != nil {
log.Error("Error scanning Library", "folder", library, err)
}
@@ -241,7 +241,7 @@ func (s *scanner) loadFolders() {
libs, _ := s.ds.Library(ctx).GetAll()
for _, lib := range libs {
log.Info("Configuring Media Folder", "name", lib.Name, "path", lib.Path)
- s.folders[lib.Path] = s.newScanner(lib)
+ s.folders[lib.Path] = s.newScanner()
s.libs[lib.Path] = lib
s.status[lib.Path] = &scanStatus{
active: false,
@@ -252,6 +252,6 @@ func (s *scanner) loadFolders() {
}
}
-func (s *scanner) newScanner(f model.Library) FolderScanner {
- return NewTagScanner(f, s.ds, s.pls, s.cacheWarmer)
+func (s *scanner) newScanner() FolderScanner {
+ return NewTagScanner(s.ds, s.pls, s.cacheWarmer)
}
diff --git a/scanner/tag_scanner.go b/scanner/tag_scanner.go
index 12877aabe..b1b1f20f6 100644
--- a/scanner/tag_scanner.go
+++ b/scanner/tag_scanner.go
@@ -25,20 +25,22 @@ import (
)
type TagScanner struct {
- lib model.Library
+ // Dependencies
ds model.DataStore
- plsSync *playlistImporter
- cnt *counters
- mapper *MediaFileMapper
+ playlists core.Playlists
cacheWarmer artwork.CacheWarmer
+
+ // Internal state
+ lib model.Library
+ cnt *counters
+ mapper *MediaFileMapper
}
-func NewTagScanner(lib model.Library, ds model.DataStore, playlists core.Playlists, cacheWarmer artwork.CacheWarmer) FolderScanner {
+func NewTagScanner(ds model.DataStore, playlists core.Playlists, cacheWarmer artwork.CacheWarmer) FolderScanner {
s := &TagScanner{
- lib: lib,
- plsSync: newPlaylistImporter(ds, playlists, cacheWarmer, lib.Path),
ds: ds,
cacheWarmer: cacheWarmer,
+ playlists: playlists,
}
metadata.LogExtractors()
@@ -77,10 +79,13 @@ const (
// - If the playlist is not in the DB, import it, setting sync = true
// - If the playlist is in the DB and sync == true, import it, or else skip it
// Delete all empty albums, delete all empty artists, clean-up playlists
-func (s *TagScanner) Scan(ctx context.Context, fullScan bool, progress chan uint32) (int64, error) {
+func (s *TagScanner) Scan(ctx context.Context, lib model.Library, fullScan bool, progress chan uint32) (int64, error) {
ctx = auth.WithAdminUser(ctx, s.ds)
start := time.Now()
+ // Update internal copy of Library
+ s.lib = lib
+
// Special case: if LastScanAt is zero, re-import all files
fullScan = fullScan || s.lib.LastScanAt.IsZero()
@@ -164,7 +169,8 @@ func (s *TagScanner) Scan(ctx context.Context, fullScan bool, progress chan uint
log.Warn("Playlists will not be imported, as there are no admin users yet, "+
"Please create an admin user first, and then update the playlists for them to be imported", "dir", dir)
} else {
- s.cnt.playlists = s.plsSync.processPlaylists(ctx, dir)
+ plsSync := newPlaylistImporter(s.ds, s.playlists, s.cacheWarmer, lib.Path)
+ s.cnt.playlists = plsSync.processPlaylists(ctx, dir)
}
}
}