Fix tournament haystack previous cursor - #2540
Open
yaosongding wants to merge 2 commits into
Open
Conversation
TournamentRecordsHaystack incorrectly assigned the next cursor value to the previous cursor field, breaking backward pagination on tournament records around an owner. Fixes a copy-paste error present since the haystack cursors feature was introduced. Adds an API-level test asserting the previous and next cursors are distinct and that the previous cursor is usable.
yaosongding
marked this pull request as ready for review
August 13, 2026 13:00
Assert the exact middle-page contents (scores 40/30/20, ranks 2/3/4), verify the previous cursor returns the record ranked above the page (score 50, rank 1) and the next cursor the record below (score 10, rank 5), and that all three pages cover every record exactly once. Also close the API server database connection instead of an unused one.
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
Fixes a copy-paste bug in
TournamentRecordsHaystackwhere the previous cursor was assigned the value of the next cursor:Impact
Clients paginating backward through
ListTournamentRecordsAroundOwnerreceive a next-page cursor where a previous-page cursor belongs. Following the returnedprev_cursorlands on the next page (duplicated forward navigation), and when the leaderboard end leaves no next cursor, no previous cursor is returned at all — backward pagination is broken in both cases.Evidence
5666361a("Add leaderboard record list around owner cursors", Add leaderboard record list around owner cursors #877, 2022) and present since. The sibling path in the same file —TournamentRecordsList(core_tournament.go) — already mapsPrevCursor: records.PrevCursorcorrectly, as doesLeaderboardRecordsHaystack(core_leaderboard.go). Only the haystack wrapper dropped it.results.PrevCursorhas been correct and populated the entire time — only the tournament wrapper dropped it.Test
Adds
TestApiTournamentHaystack(server/api_tournament_test.go), an API-level test that:enable_ranksWriteTournamentRecord(scores 10–50, so the owner at score 30 sits at rank 3)ListTournamentRecordsAroundOwnerfrom the middle with a small limit (3)PrevCursor != NextCursorprev_cursorreturns the single record ranked above the middle page (score 50, rank 1), and followingnext_cursorreturns the single record ranked below (score 10, rank 5)Verified: test FAILS on the buggy code (the cursor-inequality assertion and the previous-page content assertion both fail — the buggy
prev_cursorreturns the score-10 record instead of the score-50 record), PASSES with the fix.Verification
go build ./server/— passesgolangci-lint run --new-from-rev=master ./server/— 0 issues