fix artist refreshstats query

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan
2025-11-01 15:21:24 -04:00
parent 4f1732f186
commit 4994ae0aed
3 changed files with 10 additions and 1 deletions

View File

@@ -63,6 +63,8 @@ func trackScanAsSubprocess(ctx context.Context, progress <-chan *scanner.Progres
}
func runScanner(ctx context.Context) {
defer db.Init(ctx)()
sqlDB := db.Db()
defer db.Db().Close()
ds := persistence.New(sqlDB)

View File

@@ -0,0 +1,7 @@
-- +goose Up
-- Add index on artist_id for media_file_artists table to improve query performance
-- This index is crucial for the RefreshStats query in artistRepository
CREATE INDEX IF NOT EXISTS media_file_artists_artist_id ON media_file_artists(artist_id);
-- +goose Down
DROP INDEX IF EXISTS media_file_artists_artist_id;

View File

@@ -399,7 +399,7 @@ func (r *artistRepository) RefreshStats(allArtists bool) (int64, error) {
}
// Template for the batch update with placeholder markers that we'll replace
// This now calculates per-library statistics and stores them in library_artist.stats
// This calculates per-library statistics and stores them in library_artist.stats
batchUpdateStatsSQL := `
WITH artist_role_counters AS (
SELECT mfa.artist_id,