Replace custom chunking logic with a utils.BreakUpStringSlice call

This commit is contained in:
Deluan 2021-02-03 17:26:03 -05:00 committed by Joe Stump
parent 0a7a06bdc9
commit 7cdbf3c217
No known key found for this signature in database
GPG Key ID: 29151C3EC48A0EB9

View File

@ -9,6 +9,7 @@ import (
"github.com/astaxie/beego/orm"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/utils"
)
type playQueueRepository struct {
@ -112,16 +113,7 @@ func (r *playQueueRepository) loadTracks(tracks model.MediaFiles) model.MediaFil
}
// Break the list in chunks, up to 50 items, to avoid hitting SQLITE_MAX_FUNCTION_ARG limit
const chunkSize = 50
var chunks [][]string
for i := 0; i < len(ids); i += chunkSize {
end := i + chunkSize
if end > len(ids) {
end = len(ids)
}
chunks = append(chunks, ids[i:end])
}
chunks := utils.BreakUpStringSlice(ids, 50)
// Query each chunk of media_file ids and store results in a map
mfRepo := NewMediaFileRepository(r.ctx, r.ormer)