fix(recommendation): Rediscover no longer ships a one-song playlist (#1246)
Confirmed against prod: exactly one track (17 plays, cold since May 21) met the c>=5 + 30d-cold bar, and three process defects turned that into a 1-track playlist instead of the locked placeholder. - ListRediscoverTracks: collapse the two-tier UNION into one blended pool. The old shallow-tier gate (WHERE NOT EXISTS deep) was all-or-nothing — one 6-month row suppressed the entire 30-day tier — and deep was a strict subset of shallow anyway. Eligibility drops to >=3 non-skip plays (on a weeks-old history the >=5-play tracks are precisely the ones still in rotation); ordering prefers >=6mo cold, then >=5 plays, then raw count. - Minimum viable mix floor for all five discovery mixes: below minLen (15; 5 for the album-coherent NewForYou/FirstListens) the variant is withheld so Home renders the 'listen more to unlock' placeholder instead of a mix that reads as built-wrong. - /api/events: clamp client-supplied 'at' to [user.created_at, now+5m]. Unbounded client clocks could write arbitrarily old plays and poison the 6-month ordering (prod data verified clean — no scrub needed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsF3cNoKrqCYsU78cXC8U6
This commit is contained in:
@@ -262,37 +262,19 @@ WITH stats AS (
|
||||
FROM play_events pe
|
||||
WHERE pe.user_id = $1 AND pe.was_skipped = false
|
||||
GROUP BY pe.track_id
|
||||
),
|
||||
deep AS (
|
||||
SELECT t.id, t.album_id, t.artist_id, s.c, 0 AS tier
|
||||
FROM tracks t
|
||||
JOIN stats s ON s.track_id = t.id
|
||||
WHERE s.c >= 5
|
||||
AND s.last_at <= now() - interval '6 months'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM lidarr_quarantine q
|
||||
WHERE q.user_id = $1 AND q.track_id = t.id
|
||||
)
|
||||
),
|
||||
shallow AS (
|
||||
SELECT t.id, t.album_id, t.artist_id, s.c, 1 AS tier
|
||||
FROM tracks t
|
||||
JOIN stats s ON s.track_id = t.id
|
||||
WHERE s.c >= 5
|
||||
AND s.last_at <= now() - interval '30 days'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM lidarr_quarantine q
|
||||
WHERE q.user_id = $1 AND q.track_id = t.id
|
||||
)
|
||||
)
|
||||
SELECT id, album_id, artist_id
|
||||
FROM (
|
||||
SELECT id, album_id, artist_id, c, tier FROM deep
|
||||
UNION ALL
|
||||
SELECT id, album_id, artist_id, c, tier FROM shallow
|
||||
WHERE NOT EXISTS (SELECT 1 FROM deep)
|
||||
) u
|
||||
ORDER BY tier, c DESC, id
|
||||
SELECT t.id, t.album_id, t.artist_id
|
||||
FROM tracks t
|
||||
JOIN stats s ON s.track_id = t.id
|
||||
WHERE s.c >= 3
|
||||
AND s.last_at <= now() - interval '30 days'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM lidarr_quarantine q
|
||||
WHERE q.user_id = $1 AND q.track_id = t.id
|
||||
)
|
||||
ORDER BY (s.last_at <= now() - interval '6 months') DESC,
|
||||
(s.c >= 5) DESC,
|
||||
s.c DESC, t.id
|
||||
LIMIT 200
|
||||
`
|
||||
|
||||
@@ -302,13 +284,17 @@ type ListRediscoverTracksRow struct {
|
||||
ArtistID pgtype.UUID
|
||||
}
|
||||
|
||||
// #420 Rediscover: tracks the user played a lot (>=5 non-skip) but
|
||||
// has drifted away from. Tiered so a young library still gets a mix:
|
||||
//
|
||||
// tier 0 not played in the last 6 months (true rediscovery)
|
||||
// tier 1 (only if tier 0 empty) not played in the last 30 days
|
||||
//
|
||||
// Ordered by historical affection. $1 user_id.
|
||||
// #420 Rediscover: tracks the user played a lot but has drifted away
|
||||
// from. One blended pool (issue #1246: the old two-tier UNION was
|
||||
// all-or-nothing — a single ">=6 months cold" row suppressed the whole
|
||||
// ">=30 days" tier, which is how a one-song playlist shipped; the 6mo
|
||||
// tier was also a strict subset of the 30d tier). Eligibility is >=3
|
||||
// non-skip plays and >=30 days cold; the bar sits at 3 rather than 5
|
||||
// so a weeks-old library still fields a pool — on young histories the
|
||||
// >=5-play tracks are precisely the ones still in rotation. Ordering
|
||||
// prefers true rediscoveries (>=6 months cold), then strong affection
|
||||
// (>=5 plays), then raw play count; the producer's minimum floor
|
||||
// decides whether the pool is big enough to ship at all. $1 user_id.
|
||||
func (q *Queries) ListRediscoverTracks(ctx context.Context, userID pgtype.UUID) ([]ListRediscoverTracksRow, error) {
|
||||
rows, err := q.db.Query(ctx, listRediscoverTracks, userID)
|
||||
if err != nil {
|
||||
|
||||
@@ -37,47 +37,35 @@ SELECT t.id, t.album_id, t.artist_id
|
||||
LIMIT 200;
|
||||
|
||||
-- name: ListRediscoverTracks :many
|
||||
-- #420 Rediscover: tracks the user played a lot (>=5 non-skip) but
|
||||
-- has drifted away from. Tiered so a young library still gets a mix:
|
||||
-- tier 0 not played in the last 6 months (true rediscovery)
|
||||
-- tier 1 (only if tier 0 empty) not played in the last 30 days
|
||||
-- Ordered by historical affection. $1 user_id.
|
||||
-- #420 Rediscover: tracks the user played a lot but has drifted away
|
||||
-- from. One blended pool (issue #1246: the old two-tier UNION was
|
||||
-- all-or-nothing — a single ">=6 months cold" row suppressed the whole
|
||||
-- ">=30 days" tier, which is how a one-song playlist shipped; the 6mo
|
||||
-- tier was also a strict subset of the 30d tier). Eligibility is >=3
|
||||
-- non-skip plays and >=30 days cold; the bar sits at 3 rather than 5
|
||||
-- so a weeks-old library still fields a pool — on young histories the
|
||||
-- >=5-play tracks are precisely the ones still in rotation. Ordering
|
||||
-- prefers true rediscoveries (>=6 months cold), then strong affection
|
||||
-- (>=5 plays), then raw play count; the producer's minimum floor
|
||||
-- decides whether the pool is big enough to ship at all. $1 user_id.
|
||||
WITH stats AS (
|
||||
SELECT pe.track_id, COUNT(*) AS c, MAX(pe.started_at) AS last_at
|
||||
FROM play_events pe
|
||||
WHERE pe.user_id = $1 AND pe.was_skipped = false
|
||||
GROUP BY pe.track_id
|
||||
),
|
||||
deep AS (
|
||||
SELECT t.id, t.album_id, t.artist_id, s.c, 0 AS tier
|
||||
FROM tracks t
|
||||
JOIN stats s ON s.track_id = t.id
|
||||
WHERE s.c >= 5
|
||||
AND s.last_at <= now() - interval '6 months'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM lidarr_quarantine q
|
||||
WHERE q.user_id = $1 AND q.track_id = t.id
|
||||
)
|
||||
),
|
||||
shallow AS (
|
||||
SELECT t.id, t.album_id, t.artist_id, s.c, 1 AS tier
|
||||
FROM tracks t
|
||||
JOIN stats s ON s.track_id = t.id
|
||||
WHERE s.c >= 5
|
||||
AND s.last_at <= now() - interval '30 days'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM lidarr_quarantine q
|
||||
WHERE q.user_id = $1 AND q.track_id = t.id
|
||||
)
|
||||
)
|
||||
SELECT id, album_id, artist_id
|
||||
FROM (
|
||||
SELECT id, album_id, artist_id, c, tier FROM deep
|
||||
UNION ALL
|
||||
SELECT id, album_id, artist_id, c, tier FROM shallow
|
||||
WHERE NOT EXISTS (SELECT 1 FROM deep)
|
||||
) u
|
||||
ORDER BY tier, c DESC, id
|
||||
SELECT t.id, t.album_id, t.artist_id
|
||||
FROM tracks t
|
||||
JOIN stats s ON s.track_id = t.id
|
||||
WHERE s.c >= 3
|
||||
AND s.last_at <= now() - interval '30 days'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM lidarr_quarantine q
|
||||
WHERE q.user_id = $1 AND q.track_id = t.id
|
||||
)
|
||||
ORDER BY (s.last_at <= now() - interval '6 months') DESC,
|
||||
(s.c >= 5) DESC,
|
||||
s.c DESC, t.id
|
||||
LIMIT 200;
|
||||
|
||||
-- name: ListNewForYouTracks :many
|
||||
|
||||
Reference in New Issue
Block a user