audio streaming app plyr.fm
38
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: show all-time like count on period-filtered top tracks (#1230)

Period filtering should only affect which tracks appear and their
ordering, not the displayed like_count. Previously, the endpoint
reused the period-scoped count for display, so "past day" showed
"1 like" even if a track had many total likes.

Now fetches all-time like counts separately for the response while
still using period-filtered counts for ranking.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

authored by

nate nowack
Claude Opus 4.6
and committed by
GitHub
ea7ad640 71bb075b

+27 -5
+4 -3
backend/src/backend/api/tracks/listing.py
··· 356 356 return [] 357 357 358 358 top_track_ids = [tid for tid, _ in top_tracks_with_counts] 359 - like_counts = dict(top_tracks_with_counts) 360 359 361 360 # fetch tracks with relationships 362 361 stmt = ( ··· 383 382 ) 384 383 liked_track_ids = set(liked_result.scalars().all()) 385 384 386 - # batch fetch remaining aggregations (like_counts already computed above) 387 - comment_counts, track_tags = await asyncio.gather( 385 + # batch fetch aggregations — always use all-time like counts for display 386 + # (period filtering only affects which tracks appear and their ordering) 387 + like_counts, comment_counts, track_tags = await asyncio.gather( 388 + get_like_counts(db, track_ids), 388 389 get_comment_counts(db, track_ids), 389 390 get_track_tags(db, track_ids), 390 391 )
+21
backend/tests/api/test_top_tracks.py
··· 501 501 assert "Timed Track A" in titles 502 502 assert "Timed Track B" in titles 503 503 assert "Timed Track C" not in titles 504 + 505 + 506 + async def test_top_tracks_period_shows_all_time_like_count( 507 + unauthenticated_app: FastAPI, 508 + tracks_with_timed_likes: list[Track], 509 + ): 510 + """like_count always reflects all-time total, even with period filter.""" 511 + async with AsyncClient( 512 + transport=ASGITransport(app=unauthenticated_app), 513 + base_url="http://test", 514 + ) as client: 515 + response = await client.get("/tracks/top?period=month") 516 + 517 + assert response.status_code == 200 518 + tracks = response.json() 519 + counts = {t["title"]: t["like_count"] for t in tracks} 520 + 521 + # track A has 2 total likes (1 recent + 1 old) — period only filters ordering 522 + assert counts["Timed Track A"] == 2 523 + # track B has 1 total like 524 + assert counts["Timed Track B"] == 1
+2 -2
loq.toml
··· 39 39 40 40 [[rules]] 41 41 path = "backend/src/backend/api/tracks/listing.py" 42 - max_lines = 576 42 + max_lines = 577 43 43 44 44 [[rules]] 45 45 path = "backend/src/backend/api/tracks/mutations.py" ··· 235 235 236 236 [[rules]] 237 237 path = "backend/tests/api/test_top_tracks.py" 238 - max_lines = 503 238 + max_lines = 524 239 239 240 240 [[rules]] 241 241 path = "frontend/src/routes/+page.svelte"