Skip to content

feat: add server-side pagination to leaderboard page (#637)#703

Open
Shiva210Jyoti wants to merge 7 commits into
Coder-s-OG-s:mainfrom
Shiva210Jyoti:fix/leaderboard-rate-limit-419
Open

feat: add server-side pagination to leaderboard page (#637)#703
Shiva210Jyoti wants to merge 7 commits into
Coder-s-OG-s:mainfrom
Shiva210Jyoti:fix/leaderboard-rate-limit-419

Conversation

@Shiva210Jyoti

Copy link
Copy Markdown
Contributor

Resolves #637

Summary

Implements server-side pagination for the leaderboard page using Drizzle ORM with raw SQL OFFSET/LIMIT queries.

Changes

src/app/actions/getLeaderboardPage.ts (new)

  • New server action getLeaderboardPage(page, pageSize = 20)
  • Orders profiles by XP descending with LIMIT/OFFSET
  • Returns { entries, totalCount, page, pageSize }
  • Global rank: (page - 1) * pageSize + index + 1

src/app/(app)/leaderboard/page.tsx

  • Reads page from searchParams (Next.js server component, no client state)
  • Global scope uses getLeaderboardPage, other scopes use existing getLeaderboard
  • Resolves current user rank across pages

src/app/(app)/leaderboard/leaderboard-content.tsx

  • Shows {N} CONTRIBUTORS above the table
  • Highlights current user row via entry.userId === currentUserId
  • Prev/Next as <Link href="?page=n"> matching Issues page pagination style
  • Podium shown on page 1 only

Acceptance Criteria

Requirement Status
Default page size 20
Global rank numbers across pages
URL-based pagination ?page=n
Current user highlighted across pages
Total contributor count above table
Server-side pagination (not client slice)
Prev/Next consistent with Issues page
Podium only on page 1

Notes

  • Repo uses Drizzle + raw SQL, not Prisma — same pagination concept with skip/take equivalent
  • Build clean, tsc --noEmit clean on leaderboard files

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

@Shiva210Jyoti is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Shiva210Jyoti

Copy link
Copy Markdown
Contributor Author

Hey @jakharmonika364 @Ayush-Patel-56, PR #703 is ready for review! All acceptance criteria covered, build clean. Please take a look 🙏

Comment on lines +44 to +50
* Server-side paginated global leaderboard ordered by XP descending.
* Uses OFFSET/LIMIT (Drizzle equivalent of Prisma skip/take).
* Global rank = (page - 1) * pageSize + index + 1.
*/
export async function getLeaderboardPage(
page: number,
pageSize: number = DEFAULT_PAGE_SIZE,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

order by xp desc has no tiebreaker, so ties (very common at low xp) aren't stable across separate page loads - a contributor can show up on two pages or vanish from all of them. add order by xp desc, id asc.

also this bypasses getLeaderboard entirely for the global scope, so it has no rate limit (see #688) and no cache, unlike the sibling it duplicates. and rank here is row position, not dense_rank like every other scope uses, so tied users get different ranks.

@jakharmonika364 jakharmonika364 added the Needs author reply Author need to reply label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs author reply Author need to reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pagination to the full Leaderboard page

2 participants