feat: the same song on several releases counts as one song (M498 #5438)
release / govulncheck (push) Successful in 21s
release / web (push) Successful in 1m7s
release / go (push) Successful in 1m29s
release / integration (push) Successful in 4m11s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 5m58s
release / Build signed APK (releases and dev) (push) Canceled after 5m59s

A single and the album it is on stay two files, since each fulfils its own
release in Lidarr, but they are one song to the listener.

- tracks.song_id links copies; the generated song_key (song_id, else the
  track's own id) is what they share (migration 0076).
- The resolver links each cross-release group every pass (idempotent; only
  with auto-resolve on) and, when a link is new, shares existing likes across
  the song and logs them for sync.
- A like or unlike (web and Subsonic) reaches every copy; each change is
  logged and published so clients update every heart.
- The Liked list and its count show the song once; Shuffle and the mix writer
  take one copy per song.
- A merge keeps the removed copy's song link; "Not the same song" on the
  Across releases tab dismisses the group and undoes the link.

Shared plays ("heard via another copy") are left for a later step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 22:07:55 -04:00
co-authored by Claude Opus 5.5
parent 4ecff52f19
commit 5b372f61d7
22 changed files with 799 additions and 60 deletions
+32
View File
@@ -1070,6 +1070,10 @@ func insertSystemPlaylist(ctx context.Context, qtx *dbq.Queries, userID pgtype.U
return pgtype.UUID{}, fmt.Errorf("insert playlist row: %w", err)
}
tracks, err = oneCopyPerSong(ctx, qtx, tracks)
if err != nil {
return pgtype.UUID{}, err
}
for _, t := range tracks {
var pickKind *string
if t.PickKind != "" {
@@ -1096,6 +1100,34 @@ func insertSystemPlaylist(ctx context.Context, qtx *dbq.Queries, userID pgtype.U
return p.ID, nil
}
// oneCopyPerSong keeps the first of a song's copies on different releases
// (M498 #5438): a mix holds the song once, in its best-ranked place.
func oneCopyPerSong(ctx context.Context, qtx *dbq.Queries, tracks []rankedCandidate) ([]rankedCandidate, error) {
ids := make([]pgtype.UUID, len(tracks))
for i, t := range tracks {
ids[i] = t.TrackID
}
rows, err := qtx.ListTrackSongKeys(ctx, ids)
if err != nil {
return nil, fmt.Errorf("song keys: %w", err)
}
songOf := make(map[pgtype.UUID]pgtype.UUID, len(rows))
for _, r := range rows {
songOf[r.ID] = r.SongKey
}
seen := make(map[pgtype.UUID]bool, len(tracks))
out := tracks[:0:0]
for _, t := range tracks {
song, ok := songOf[t.TrackID]
if ok && seen[song] {
continue
}
seen[song] = true
out = append(out, t)
}
return out, nil
}
// uuidStringPL renders a pgtype.UUID as the canonical 8-4-4-4-12 form.
// (pgtype.UUID's String method exists on some pgx versions but not others;
// also the playlists package needs this independent of test helpers.)