Generalize BreakUp/RangByChunks functions

This commit is contained in:
Deluan 2023-11-25 12:13:36 -05:00
parent c3efc57259
commit 9aa7b80d0d
9 changed files with 58 additions and 59 deletions

View file

@ -12,7 +12,6 @@ import (
"github.com/navidrome/navidrome/core/artwork"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/utils/slice"
"golang.org/x/exp/maps"
)
@ -71,7 +70,7 @@ func (r *refresher) flushMap(ctx context.Context, m map[string]struct{}, entity
}
ids := maps.Keys(m)
chunks := utils.BreakUpStringSlice(ids, 100)
chunks := slice.BreakUp(ids, 100)
for _, chunk := range chunks {
err := refresh(ctx, chunk...)
if err != nil {

View file

@ -19,7 +19,7 @@ import (
"github.com/navidrome/navidrome/scanner/metadata"
_ "github.com/navidrome/navidrome/scanner/metadata/ffmpeg"
_ "github.com/navidrome/navidrome/scanner/metadata/taglib"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/utils/slice"
)
type TagScanner struct {
@ -351,7 +351,7 @@ func (s *TagScanner) addOrUpdateTracksInDB(
log.Trace(ctx, "Updating mediaFiles in DB", "dir", dir, "numFiles", len(filesToUpdate))
// Break the file list in chunks to avoid calling ffmpeg with too many parameters
chunks := utils.BreakUpStringSlice(filesToUpdate, filesBatchSize)
chunks := slice.BreakUp(filesToUpdate, filesBatchSize)
for _, chunk := range chunks {
// Load tracks Metadata from the folder
newTracks, err := s.loadTracks(chunk)