Skip to content

Sum top winner across all game modes on home page#143

Open
dhoepp wants to merge 2 commits into
devfrom
fix/home-top-winner-all-modes
Open

Sum top winner across all game modes on home page#143
dhoepp wants to merge 2 commits into
devfrom
fix/home-top-winner-all-modes

Conversation

@dhoepp

@dhoepp dhoepp commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The home page "top winner" stat was calling fetchLeaderboard("infinity"), which filters the leaderboard table to mode = 'infinity' — hourly and daily play were never counted.
  • The leaderboard table has one row per (user_id, mode), so there's no single row to query for an overall winner; added fetchTopWinner() in leaderboard.ts which fetches all rows (no mode filter) and aggregates games_played/games_won/score per user_id client-side, then picks the top by score (tie-broken by games_won) — same ordering fetchLeaderboard already used.
  • Swapped LandingFeatures.tsx to use fetchTopWinner() instead.

Reviewer notes

  • fetchLeaderboard(mode) and the Leaderboard page's per-mode tabs are untouched — this only changes the home page widget.
  • No Supabase/schema changes; aggregation happens client-side since the leaderboard table doesn't have a combined-mode row.

Test plan

  • npx tsc --noEmit in frontend/ (no new errors from this change)
  • Load the home page with seeded leaderboard rows across multiple modes for the same user and confirm the "top winner" stat reflects the summed total, not just infinity-mode score

The leaderboard table has one row per (user_id, mode), so the home page's
"top winner" stat was only ever reading infinity-mode rows and missing
hourly/daily play entirely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dhoepp
dhoepp requested a review from a team July 20, 2026 11:40
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v61-tier3-team-99 Ready Ready Preview, Comment Jul 20, 2026 1:05pm

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review — see the summary comment above for the walkthrough; inline notes below.

Comment thread frontend/src/lib/leaderboard.ts
Comment thread frontend/src/lib/leaderboard.ts Outdated
@github-actions

Copy link
Copy Markdown

🤖 AI Review (Gemini 2.5 Flash)

This PR introduces a new fetchTopWinner function to display the overall top player. While the change cleanly integrates into LandingFeatures, the implementation of fetchTopWinner has significant performance and data consistency concerns. The function performs client-side aggregation and sorting of all leaderboard data, which is not scalable. Additionally, the username chosen during aggregation might be inconsistent.

Addresses PR review feedback:
- Aggregating all leaderboard rows client-side doesn't scale as the table
  grows. Added a get_top_winner() RPC (same SECURITY DEFINER aggregate-read
  pattern as get_global_game_stats) that does the per-user GROUP BY in
  Postgres and returns only the winner.
- The client-side aggregation kept whichever username it saw first for a
  user, which could be stale if they renamed themselves between mode rows.
  The RPC now picks the username from the most recently updated row.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant