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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user