Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions engine/handlers/lbz_submit_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func LbzSubmitListenHandler(store submitListenHandlerStore, mbzc mbz.MusicBrainz
SkipSaveListen: req.ListenType == ListenTypePlayingNow,
}

_, err, shared := sfGroup.Do(buildCaolescingKey(payload), func() (interface{}, error) {
_, err, shared := sfGroup.Do(buildCoalescingKey(payload, req.ListenType), func() (interface{}, error) {
return 0, catalog.SubmitListen(r.Context(), store, opts)
})
if shared {
Expand Down Expand Up @@ -315,13 +315,6 @@ func doLbzRelay(requestBytes []byte, l *zerolog.Logger) {
}
}

func buildCaolescingKey(p LbzSubmitListenPayload) string {
// the key not including the listen_type introduces the very rare possibility of a playing_now
// request taking precedence over a single, meaning that a listen will not be logged when it
// should, however that would require a playing_now request to fire a few seconds before a 'single'
// of the same track, which should never happen outside of misbehaving clients
//
// this could be fixed by restructuring the database inserts for idempotency, which would
// eliminate the need to coalesce responses, however i'm not gonna do that right now
return fmt.Sprintf("%s:%s:%s", p.TrackMeta.ArtistName, p.TrackMeta.TrackName, p.TrackMeta.ReleaseName)
func buildCoalescingKey(p LbzSubmitListenPayload, listenType LbzListenType) string {
return fmt.Sprintf("%s:%s:%s:%s", listenType, p.TrackMeta.ArtistName, p.TrackMeta.TrackName, p.TrackMeta.ReleaseName)
}