fix(playevents): a late offline replay no longer closes the play that is live now (#8074)
RecordOfflinePlay auto-closed whatever play was open at the replayed play's original, often hours-old, time. When Android drained its offline queue while the next song was already playing, each replay ended the live row before it began, as a zero-length skip. That stuck when the live play's own close was lost, and for a Subsonic app's now-playing row it became a skip plus a second play. autoClosePriorOpen now leaves open any row that started after the time it was asked to close at, for every caller; #8019's guard for the Subsonic path moves into it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -364,10 +364,8 @@ func (w *Writer) RecordSyntheticCompletedPlay(
|
||||
playEventID = open.ID
|
||||
startedAt = open.StartedAt.Time
|
||||
default:
|
||||
if hasOpen && !open.StartedAt.Time.After(at) {
|
||||
if err := w.autoClosePriorOpen(ctx, q, userID, at); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.autoClosePriorOpen(ctx, q, userID, at); err != nil {
|
||||
return err
|
||||
}
|
||||
started, err := w.openPlay(ctx, q, userID, trackID, clientID, source, "", at)
|
||||
if err != nil {
|
||||
@@ -575,6 +573,12 @@ func (w *Writer) captureSessionVector(
|
||||
// of being force-hidden. Deliberately writes no skip_events row — an
|
||||
// auto-close is an ambiguous signal, not a deliberate skip, and must not
|
||||
// feed the skip-ratio / recommendation signal.
|
||||
//
|
||||
// A row that started after at is left open: it is a later play, still live,
|
||||
// and closing it at at would end it before it began, as a zero-length skip.
|
||||
// That happens when an older play arrives late, such as an offline play
|
||||
// replayed while the next song is already playing, or a Subsonic app's
|
||||
// report of a finished listen.
|
||||
func (w *Writer) autoClosePriorOpen(
|
||||
ctx context.Context,
|
||||
q *dbq.Queries,
|
||||
@@ -588,6 +592,9 @@ func (w *Writer) autoClosePriorOpen(
|
||||
}
|
||||
return err
|
||||
}
|
||||
if prior.StartedAt.Time.After(at) {
|
||||
return nil
|
||||
}
|
||||
track, err := q.GetTrackByID(ctx, prior.TrackID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user