feat: scan the libraries by themselves when their music changed
Every 15 minutes (library.auto_scan_minutes, SONDA_AUTO_SCAN_MINUTES, 0 turns it off) Sonda takes the signature of each library, a hash of the names of everything in it folder by folder, which costs only the names of the files and so suits a NAS that sleeps. A library whose signature changed (a song or a folder came, went or was renamed) is scanned the usual way; every library is also scanned at least once a day, to find a song tagged again where it stands. It does not scan while another scan runs, tries again at the next look when a scan failed, leaves alone a folder that cannot be read (a NAS that is not mounted), and ignores the housekeeping folders of a NAS.
This commit is contained in:
parent
1b58f8412c
commit
89f1b5275a
1 changed files with 580 additions and 2 deletions
|
|
@ -153,6 +153,17 @@ func run() error {
|
|||
scanner := library.NewScanner(libraryRepo, library.TaglibReader{}, library.NewHub(), cfg.Library.ScanWorkers)
|
||||
scans := library.NewManager(scanner, libraryRepo)
|
||||
logScanResults(logger, scans)
|
||||
// The libraries are scanned by themselves when their music changed: looking costs only the names of the files.
|
||||
if cfg.Library.AutoScanMinutes > 0 {
|
||||
auto := library.NewAutoScanner(scans, libraryRepo, time.Duration(cfg.Library.AutoScanMinutes)*time.Minute)
|
||||
auto.OnScan = func(lib library.Library, signatureErr, _ error) {
|
||||
if signatureErr != nil { // a NAS that is not mounted says this all the time: not news
|
||||
logger.Debug("auto scan: the folder of a library cannot be read", zap.Int64("library", lib.ID), zap.Error(signatureErr))
|
||||
}
|
||||
}
|
||||
go auto.Run(ctx)
|
||||
logger.Info("libraries are scanned by themselves when their music changed", zap.Int("every_minutes", cfg.Library.AutoScanMinutes))
|
||||
}
|
||||
|
||||
libraries := library.NewLibraries(libraryRepo)
|
||||
libraries.SetBusy(func() bool { return scans.Status().Running })
|
||||
|
|
|
|||
Loading…
Reference in a new issue