fix: add user context to scrobble buffer getParticipants call

Added user context handling to scrobbleBufferRepository.Next method to resolve
SQL error 'no such column: library_artist.library_id' when processing scrobble
entries in multi-library environments. The artist repository now requires user
context for proper library filtering, so we fetch the user and temporarily
inject it into the context before calling getParticipants. This ensures
background scrobbling operations work correctly with multi-library support.
This commit is contained in:
Deluan 2025-07-16 20:09:47 -04:00
commit 5b8ef74f05

View file

@ -8,6 +8,7 @@ import (
. "github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/id"
"github.com/navidrome/navidrome/model/request"
"github.com/pocketbase/dbx"
)
@ -82,7 +83,20 @@ func (r *scrobbleBufferRepository) Next(service string, userId string) (*model.S
if err != nil {
return nil, err
}
// Create context with user information for getParticipants call
// This is needed because the artist repository requires user context for multi-library support
userRepo := NewUserRepository(r.ctx, r.db)
user, err := userRepo.Get(res.ScrobbleEntry.UserID)
if err != nil {
return nil, err
}
// Temporarily use user context for getParticipants
originalCtx := r.ctx
r.ctx = request.WithUser(r.ctx, *user)
res.ScrobbleEntry.Participants, err = r.getParticipants(&res.ScrobbleEntry.MediaFile)
r.ctx = originalCtx // Restore original context
if err != nil {
return nil, err
}