fix(likes): unliking any copy of a song retires the listening context captured on another (#8078)
release / go (push) Successful in 1m49s
release / web (push) Successful in 1m16s
release / govulncheck (push) Successful in 25s
release / integration (push) Failing after 4m12s
release / android (push) Successful in 4m47s
release / Build signed APK (push) Successful in 5m24s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m49s
release / web (push) Successful in 1m16s
release / govulncheck (push) Successful in 25s
release / integration (push) Failing after 4m12s
release / android (push) Successful in 4m47s
release / Build signed APK (push) Successful in 5m24s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
A like is on the song: LikeTrack and UnlikeTrack change every copy sharing its song_key. The contextual like (the session captured while it played) is written on the copy that was playing, but an unlike soft-deleted only the copy it named. Unliking from the Liked list, which shows one copy per song, or from another album holding the song, left the context active, and the engine kept boosting candidates matching it. The soft-delete now covers every copy of the song, and the engine's reader counts only contexts whose song is still liked, as a backstop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -75,3 +75,50 @@ func TestSoftDeleteContextualLikes_MarksActiveRowsDeleted(t *testing.T) {
|
||||
t.Errorf("deleted_at not set after SoftDelete")
|
||||
}
|
||||
}
|
||||
|
||||
// An unlike reaches the context captured on any copy of the song: the like
|
||||
// is on the song, and the heart can be tapped on a different copy than the
|
||||
// one that was playing.
|
||||
func TestSoftDeleteContextualLikes_ReachesEveryCopyOfTheSong(t *testing.T) {
|
||||
f := newFixture(t, 200_000)
|
||||
ctx := context.Background()
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
played := f.track
|
||||
var album, artist pgtype.UUID
|
||||
if err := f.pool.QueryRow(ctx, "SELECT album_id, artist_id FROM tracks WHERE id = $1", played).Scan(&album, &artist); err != nil {
|
||||
t.Fatalf("read track: %v", err)
|
||||
}
|
||||
other, err := f.q.UpsertTrack(ctx, dbq.UpsertTrackParams{
|
||||
Title: "Track", AlbumID: album, ArtistID: artist, FilePath: "/tmp/track-fixture-copy.flac", DurationMs: 200_000,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("copy: %v", err)
|
||||
}
|
||||
if _, err := f.pool.Exec(ctx, "UPDATE tracks SET song_id = $1 WHERE id = $2", played, other.ID); err != nil {
|
||||
t.Fatalf("link copies: %v", err)
|
||||
}
|
||||
|
||||
_, _ = f.w.RecordPlayStarted(ctx, f.user, played, "c", time.Now().UTC())
|
||||
if _, err := f.q.LikeTrack(ctx, dbq.LikeTrackParams{UserID: f.user, TrackID: played}); err != nil {
|
||||
t.Fatalf("like: %v", err)
|
||||
}
|
||||
if err := CaptureContextualLikeIfPlaying(ctx, f.q, f.user, played, logger); err != nil {
|
||||
t.Fatalf("capture: %v", err)
|
||||
}
|
||||
|
||||
// Unliked through the other copy, as from another album holding the song.
|
||||
if _, err := f.q.UnlikeTrack(ctx, dbq.UnlikeTrackParams{UserID: f.user, TrackID: other.ID}); err != nil {
|
||||
t.Fatalf("unlike: %v", err)
|
||||
}
|
||||
if err := SoftDeleteContextualLikes(ctx, f.q, f.user, other.ID); err != nil {
|
||||
t.Fatalf("SoftDelete: %v", err)
|
||||
}
|
||||
var active int
|
||||
if err := f.pool.QueryRow(ctx,
|
||||
"SELECT count(*) FROM contextual_likes WHERE user_id=$1 AND deleted_at IS NULL", f.user).Scan(&active); err != nil {
|
||||
t.Fatalf("count: %v", err)
|
||||
}
|
||||
if active != 0 {
|
||||
t.Fatalf("%d contextual likes still active after unliking the song", active)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user