perf(07-01): eliminate redundant lookups in SetQueue Phase 2

- Add phase1Meta parameter to resolveRemainingTracks
- Filter out already-resolved paths before lookupTrackMetaBatch call
- Merge Phase 1 results into Phase 2 lookup map
- Pass batchMeta from SetQueue call site to resolveRemainingTracks
- For 1000-track queue with Phase 1 resolving 50, Phase 2 now queries 950 instead of 1000
This commit is contained in:
2026-03-04 20:58:22 -05:00
parent cdd17db275
commit ced58fe6a9
4 changed files with 134 additions and 23 deletions
+20 -2
View File
@@ -250,7 +250,7 @@ func (q *Queue) SetQueue(
return
}
go q.resolveRemainingTracks(gen, filePaths, playingPath)
go q.resolveRemainingTracks(gen, filePaths, playingPath, batchMeta)
}
// resolveRemainingTracks runs in a goroutine to batch-resolve all tracks
@@ -258,12 +258,30 @@ func (q *Queue) SetQueue(
// results to avoid overwriting a newer SetQueue call. playingPath is the
// file path of the track that is currently playing so the correct
// currentIndex can be located in the rebuilt track list.
// phase1Meta contains metadata already resolved in Phase 1; those paths
// are skipped to avoid redundant database lookups.
func (q *Queue) resolveRemainingTracks(
gen int64,
filePaths []string,
playingPath string,
phase1Meta map[string]trackMeta,
) {
allMeta := q.lookupTrackMetaBatch(filePaths)
// Exclude paths already resolved in Phase 1.
var unresolvedPaths []string
for _, fp := range filePaths {
if _, alreadyResolved := phase1Meta[fp]; !alreadyResolved {
unresolvedPaths = append(unresolvedPaths, fp)
}
}
// Only look up paths that Phase 1 didn't cover.
allMeta := q.lookupTrackMetaBatch(unresolvedPaths)
// Merge Phase 1 results into the lookup.
for k, v := range phase1Meta {
allMeta[k] = v
}
// Check if we have been superseded before acquiring the mutex.
if q.setQueueGen.Load() != gen {