fix(indexer): dense-competitive rank on referrer leaderboard (GitLab #177) #376

Merged
Brouie merged 1 commit from fix/glab-177-referrer-leaderboard-dense-rank into main 2026-05-07 11:59:47 +00:00
Brouie commented 2026-05-07 03:11:39 +00:00 (Migrated from gitlab.com)

closes #177.

what changed

  • indexer/src/api.rs:1913-1928 — referrer-leaderboard SQL rewritten with inner subquery + RANK() OVER (ORDER BY COALESCE(SUM(referrer_amount), 0) DESC NULLS LAST)::bigint, outer ORDER BY rank ASC, referrer ASC preserves deterministic pagination across tied groups.
  • indexer/src/api.rs:1940-1949 — handler drops enumerate() page-ordinal computation, reads rank directly from SQL via r.try_get::<i64, _>("rank").
  • indexer/src/api.rs:24 — SCHEMA_VERSION bumps 1.16.1 → 1.17.0 to reflect value-semantic shift on the existing rank field.
  • indexer/tests/integration_stage2.rs — new postgres-gated test postgres_gitlab177_referrer_leaderboard_dense_rank seeds 4 referrers with amounts 300/200/200/100, asserts ranks 1, 2, 2, 4 with referrer ASC tiebreaker between tied bbbb/cccc, pins paginated tie behavior at offset=2 returning ranks [2, 4] (not [3, 4] as page-ordinal would have given).

why

#170 follow-up flagged that rank was page ordinal and you confirmed dense-competitive is the desired behavior under ties (1, 2, 2, 4 pattern). this lands that change.

verification

  • cargo check clean, cargo clippy --all-targets -- -D warnings clean.
  • cargo test (no postgres URL) — 40 unit + 0 doc + 3 integration = 43 PASS, postgres-gated tests skip cleanly per the existing harness pattern.
  • cargo test postgres_gitlab177 -- --nocapture against the QA test DB — 1 PASS, dense-rank logic exercised end-to-end via real HTTP requests through the axum router. seed → request → assert ranks → assert paginated tie behavior → cleanup.

consumer impact

frontend ReferralLeaderboardSection.tsx:120 uses row.rank === 1 for --first styling. under ties at the top, multiple rows now get the gold-first treatment — assumed desired UX given the spec change. :126 renders #{row.rank} literally — ties read #1, #1, #3 which is visually correct. no other consumer of the rank field on this endpoint in the frontend.

cc @PlasticDigits

closes #177. ## what changed - `indexer/src/api.rs:1913-1928` — referrer-leaderboard SQL rewritten with inner subquery + `RANK() OVER (ORDER BY COALESCE(SUM(referrer_amount), 0) DESC NULLS LAST)::bigint`, outer `ORDER BY rank ASC, referrer ASC` preserves deterministic pagination across tied groups. - `indexer/src/api.rs:1940-1949` — handler drops `enumerate()` page-ordinal computation, reads `rank` directly from SQL via `r.try_get::<i64, _>("rank")`. - `indexer/src/api.rs:24` — `SCHEMA_VERSION` bumps `1.16.1` → `1.17.0` to reflect value-semantic shift on the existing `rank` field. - `indexer/tests/integration_stage2.rs` — new postgres-gated test `postgres_gitlab177_referrer_leaderboard_dense_rank` seeds 4 referrers with amounts `300/200/200/100`, asserts ranks `1, 2, 2, 4` with `referrer ASC` tiebreaker between tied bbbb/cccc, pins paginated tie behavior at `offset=2` returning ranks `[2, 4]` (not `[3, 4]` as page-ordinal would have given). ## why #170 follow-up flagged that `rank` was page ordinal and you confirmed dense-competitive is the desired behavior under ties (1, 2, 2, 4 pattern). this lands that change. ## verification - `cargo check` clean, `cargo clippy --all-targets -- -D warnings` clean. - `cargo test` (no postgres URL) — 40 unit + 0 doc + 3 integration = 43 PASS, postgres-gated tests skip cleanly per the existing harness pattern. - `cargo test postgres_gitlab177 -- --nocapture` against the QA test DB — 1 PASS, dense-rank logic exercised end-to-end via real HTTP requests through the axum router. seed → request → assert ranks → assert paginated tie behavior → cleanup. ## consumer impact frontend `ReferralLeaderboardSection.tsx:120` uses `row.rank === 1` for `--first` styling. under ties at the top, multiple rows now get the gold-first treatment — assumed desired UX given the spec change. `:126` renders `#{row.rank}` literally — ties read `#1, #1, #3` which is visually correct. no other consumer of the `rank` field on this endpoint in the frontend. cc @PlasticDigits
PlasticDigits commented 2026-05-07 11:59:47 +00:00 (Migrated from gitlab.com)

mentioned in commit 86f08ba0af

mentioned in commit 86f08ba0af500bea2d48e8650c6e5ccfc5cb09a1
PlasticDigits (Migrated from gitlab.com) merged commit 86f08ba0af into main 2026-05-07 11:59:47 +00:00
PlasticDigits commented 2026-05-13 15:13:33 +00:00 (Migrated from gitlab.com)

mentioned in commit e8a2399d37

mentioned in commit e8a2399d37d9ac15f72fb7f6767c993beafd9a2b
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code/yieldomega!376
No description provided.