fix(leaderboard): use competition ranks for all-time ties - #655
Merged
IvGolovach merged 1 commit intoJun 4, 2026
Merged
Conversation
Validation * Validation tier: Tier 2 - Narrow Runtime Change, focused frontend leaderboard/embed rank semantics. * bun install --frozen-lockfile: PASS * bun x vitest run __tests__/lib/getLeaderboardAllTime.test.ts __tests__/lib/getUserEmbedStats.test.ts: PASS, 10 tests * bun x vitest run __tests__/lib/getLeaderboardAllTime.test.ts __tests__/lib/getLeaderboard.test.ts __tests__/lib/getUserEmbedStats.test.ts __tests__/api/usersProfile.test.ts: PASS, 22 tests * bun x eslint src/lib/leaderboard/getLeaderboard.ts src/lib/embed/getUserEmbedStats.ts __tests__/lib/getLeaderboardAllTime.test.ts __tests__/lib/getUserEmbedStats.test.ts: PASS * git diff --check: PASS * git diff --cached --check: PASS * Ledger: not applicable - not required for selected validation tier/change family. * Version: not applicable - not required for selected validation tier/change family. * Not run: full frontend test suite - not required for selected validation tier. Rollback * git revert HEAD
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
All-time leaderboard ties could display inconsistent ranks depending on whether the user was looking at the paginated list, search results, or embed/profile-adjacent rank data. The SQL already has the right place to compute stable rank semantics, so this change makes ranking authoritative at the query layer and avoids client-side offset recalculation that breaks ties.
Diff scope
packages/frontend/src/lib/leaderboard/getLeaderboard.ts: computes all-time ranks with SQLRANK()and preserves those ranks in list/search responses while keeping deterministic secondary ordering outside the rank expression.packages/frontend/src/lib/embed/getUserEmbedStats.ts: computes embed rank windows on the selected metric only, so tied totals share a rank consistently.packages/frontend/__tests__/lib/getLeaderboardAllTime.test.ts: adds coverage for competition ranks and tied list/search behavior.packages/frontend/__tests__/lib/getUserEmbedStats.test.ts: adds coverage proving embed rank SQL does not include deterministic display tie-breakers inside the rank window.Branch integrity
main.a86e688d620939d2c973c6d5625baa815ea223d7.0 behind / 1 aheadagainstorigin/main.a86e688d620939d2c973c6d5625baa815ea223d7.origin/mainis an ancestor of this branch.Commit integrity
85bbd9767d87c7095852f6fe8448b691bb2a7d97 fix(leaderboard): use competition ranks for all-time ties.Diff hygiene
git diff --name-status origin/main...HEAD: only leaderboard/embed rank logic and focused tests changed.git diff --check origin/main...HEAD: PASS, no output.Validation mode and proof
Mode 2 - narrow runtime change, because the diff changes focused frontend leaderboard/embed query semantics without touching auth, migrations, deployment tooling, or broader API contracts.
bun x vitest run __tests__/lib/getLeaderboardAllTime.test.tsfailed before the implementation because all-time list/search SQL lacked authoritative competition ranks and tied rows could receive offset-derived ranks.bun x vitest run __tests__/lib/getUserEmbedStats.test.tsfailed before the implementation because embed rank windows included secondary tie-breakers in the rank expression.bun x vitest run __tests__/lib/getLeaderboardAllTime.test.ts __tests__/lib/getLeaderboard.test.ts __tests__/lib/getUserEmbedStats.test.ts __tests__/api/usersProfile.test.ts: PASS, 4 files and 22 tests.bun x eslint src/lib/leaderboard/getLeaderboard.ts src/lib/embed/getUserEmbedStats.ts __tests__/lib/getLeaderboardAllTime.test.ts __tests__/lib/getUserEmbedStats.test.ts: PASS, no output.git diff --check origin/main...HEAD: PASS, no output.Required remote gates
Pending - GitHub Actions, Vercel, and mergeability checks will run after the PR is opened.
Migration notes
Not applicable - no database migration changed.
Runtime safety
The change only alters rank calculation semantics for existing leaderboard/embed reads. It does not change stored usage data, submission totals, auth behavior, or write paths. Deterministic ordering remains in place for display stability, but it no longer changes the rank assigned to tied totals. No invariant regression introduced.
Documentation integrity
Not applicable - no docs, commands, or runbooks changed.
Rollback plan
Rollback: revert this PR. DB downgrade: not applicable. Data repair: not applicable. Operational caveats: reverting would restore inconsistent all-time tie ranks across leaderboard views.
Known residual risks
Remote CI and GitHub mergeability are pending until the PR is opened. This PR intentionally keeps existing deterministic display ordering, so users with tied totals can still appear in a stable order while sharing the same competition rank.
Summary by cubic
Fixes inconsistent all-time leaderboard ranks for ties by using competition ranking (
RANK()) and returning the DB-computed rank. Ranks now match across list, search, and embeds while keeping stable display order.RANK()for all-time ranks inpackages/frontend/src/lib/leaderboard/getLeaderboard.ts; keep secondary deterministic ordering outside the rank and return the DB rank instead of offset.packages/frontend/src/lib/embed/getUserEmbedStats.tsso tied totals share the same rank.packages/frontend/__tests__/lib/getLeaderboardAllTime.test.tsandpackages/frontend/__tests__/lib/getUserEmbedStats.test.ts.Written for commit 85bbd97. Summary will update on new commits.