diff --git a/core/scrobbler/play_tracker.go b/core/scrobbler/play_tracker.go index 5ff346845..64dea0697 100644 --- a/core/scrobbler/play_tracker.go +++ b/core/scrobbler/play_tracker.go @@ -124,7 +124,7 @@ func (p *playTracker) Submit(ctx context.Context, submissions []Submission) erro success := 0 for _, s := range submissions { - mf, err := p.ds.MediaFile(ctx).Get(s.TrackID) + mf, err := p.ds.MediaFile(ctx).GetWithParticipants(s.TrackID) if err != nil { log.Error(ctx, "Cannot find track for scrobbling", "id", s.TrackID, "user", username, err) continue diff --git a/persistence/mediafile_repository.go b/persistence/mediafile_repository.go index 59d171996..ef4507877 100644 --- a/persistence/mediafile_repository.go +++ b/persistence/mediafile_repository.go @@ -150,27 +150,6 @@ func (r *mediaFileRepository) GetWithParticipants(id string) (*model.MediaFile, return m, err } -func (r *mediaFileRepository) getParticipants(m *model.MediaFile) (model.Participants, error) { - ar := NewArtistRepository(r.ctx, r.db) - ids := m.Participants.AllIDs() - artists, err := ar.GetAll(model.QueryOptions{Filters: Eq{"id": ids}}) - if err != nil { - return nil, fmt.Errorf("getting participants: %w", err) - } - artistMap := slice.ToMap(artists, func(a model.Artist) (string, model.Artist) { - return a.ID, a - }) - p := m.Participants - for role, artistList := range p { - for idx, artist := range artistList { - if a, ok := artistMap[artist.ID]; ok { - p[role][idx].Artist = a - } - } - } - return p, nil -} - func (r *mediaFileRepository) GetAll(options ...model.QueryOptions) (model.MediaFiles, error) { sq := r.selectMediaFile(options...) var res dbMediaFiles diff --git a/persistence/scrobble_buffer_repository.go b/persistence/scrobble_buffer_repository.go index 704386b4a..d0f88903e 100644 --- a/persistence/scrobble_buffer_repository.go +++ b/persistence/scrobble_buffer_repository.go @@ -82,6 +82,10 @@ func (r *scrobbleBufferRepository) Next(service string, userId string) (*model.S if err != nil { return nil, err } + res.ScrobbleEntry.Participants, err = r.getParticipants(&res.ScrobbleEntry.MediaFile) + if err != nil { + return nil, err + } return res.ScrobbleEntry, nil } diff --git a/persistence/sql_participations.go b/persistence/sql_participations.go index 3fa2e7c8b..006b7063b 100644 --- a/persistence/sql_participations.go +++ b/persistence/sql_participations.go @@ -64,3 +64,24 @@ func (r sqlRepository) updateParticipants(itemID string, participants model.Part _, err = r.executeSQL(sqi) return err } + +func (r *sqlRepository) getParticipants(m *model.MediaFile) (model.Participants, error) { + ar := NewArtistRepository(r.ctx, r.db) + ids := m.Participants.AllIDs() + artists, err := ar.GetAll(model.QueryOptions{Filters: Eq{"id": ids}}) + if err != nil { + return nil, fmt.Errorf("getting participants: %w", err) + } + artistMap := slice.ToMap(artists, func(a model.Artist) (string, model.Artist) { + return a.ID, a + }) + p := m.Participants + for role, artistList := range p { + for idx, artist := range artistList { + if a, ok := artistMap[artist.ID]; ok { + p[role][idx].Artist = a + } + } + } + return p, nil +}