Indexer: referrer leaderboard rank should be dense-competitive (RANK() over SUM), not page ordinal #177
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:open_issues
agents
agent:security_audit
agent:verify
area
timecurve
arena
arena-v2
audit
block:feature_review
block:security
bug
contracts
design
devops
docs
documentation
enhancement
epic
feature
frontend
indexer
low priority
megaeth
operations
ops
performance
QA
qa checklist
referrals
removal
security
smart-contracts
tech-debt
testing
time-arena
timecurve
visual-qa
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/yieldomega#177
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
split out from #170 follow-up — @PlasticDigits confirmed "Yes we do need to show true placement under ties".
current behavior at HEAD
284c15cGET /v1/referrals/referrer-leaderboardatindexer/src/api.rs:1907-1964. handler buildsrankfield as page ordinal:so the first row of
?limit=10&offset=20is rank 21 regardless of how many tie-groups precede it. SQL post-#170 fix isORDER BY SUM(referrer_amount) DESC NULLS LAST, referrer ASC— pagination is deterministic but rank is page-position, not leaderboard-position.desired: dense-competitive rank where ties share the same numeric rank and the next non-tied entry skips past them (1, 2, 2, 4 — the example you cited in the #170 follow-up).
fix shape
window function over the grouped sum, computed in the SQL layer:
RANK()(notDENSE_RANK()) gives the 1, 2, 2, 4 pattern you specified. inner subquery is required becauseRANK()cannot reference an aggregate alias from the same SELECT. tiebreakerreferrer ASCpreserved at outer level for deterministic pagination across equal ranks.handler change at
:1935-1946— drop theenumerate()ordinal, readrankfrom the SQL column:consumer impact
frontend
ReferralLeaderboardSection.tsx:120usesrow.rank === 1for--firststyling. under ties at the top, multiple rows would now get the gold-first treatment. probably the desired UX behavior given the spec change but worth confirming.ReferralLeaderboardSection.tsx:126renders#{row.rank}literally — ties read#1, #1, #3which is visually correct.no other consumer of the
rankfield on this endpoint in the frontend.schema versioning
value semantics on the
rankfield shift (page-ordinal → leaderboard-rank); field name unchanged. consistent with #170 / #168 precedent of bumping on response semantic changes — recommendSCHEMA_VERSIONfrom1.16.1→1.17.0(additive semantic, no field removal). updateapi.rs:24.test coverage
extend
indexer/tests/integration_stage2.rs:idx_timecurve_referral_appliedrows where two referrers tie onSUM(referrer_amount)rankvalues and the row directly after them hasrank = tied_rank + tie_count(e.g. tied at 1 → next is 3; tied at 2 → next is 4 per your example)?limit=2&offset=0returns ranks[1,2],?limit=2&offset=2returns ranks[2,4]or whatever the seeded distribution requiresacceptance criteria
RANK() OVER (...)window function computes rank in SQL, not in handlerrankvalues, next rank skips by tie-countcargo test+cargo clippy --all-targets -- -D warningscleanhappy to ship as a small MR if you want it off your queue — SQL rewrite + handler row-mapping + schema bump + integration test addition is a tight patch.
cc @PlasticDigits
mentioned in issue #170
mentioned in merge request !376
mentioned in commit
86f08ba0afmentioned in commit
a57d0d9611mentioned in issue #204
mentioned in merge request !390
mentioned in issue #225