fix(server): throttle events sent to UI when scanning. Relates to #1511

See also: https://github.com/navidrome/navidrome/issues/1186#issuecomment-1554818537
This commit is contained in:
Deluan
2024-09-26 18:14:00 -04:00
parent 76614b8f16
commit 80acfc103f
4 changed files with 20 additions and 6 deletions
+8 -1
View File
@@ -118,7 +118,7 @@ func (s *TagScanner) Scan(ctx context.Context, lib model.Library, fullScan bool,
g, walkCtx := errgroup.WithContext(ctx)
g.Go(func() error {
for folderStats := range pl.ReadOrDone(walkCtx, foldersFound) {
progress <- folderStats.AudioFilesCount
updateProgress(progress, folderStats.AudioFilesCount)
allFSDirs[folderStats.Path] = folderStats
if s.folderHasChanged(folderStats, allDBDirs, s.lib.LastScanAt) || fullScan {
@@ -185,6 +185,13 @@ func (s *TagScanner) Scan(ctx context.Context, lib model.Library, fullScan bool,
return s.cnt.total(), err
}
func updateProgress(progress chan uint32, count uint32) {
select {
case progress <- count:
default: // It is ok to miss a count update
}
}
func isDirEmpty(ctx context.Context, dir string) (bool, error) {
children, stats, err := loadDir(ctx, dir)
if err != nil {