Skip to content

Comments

fix(offset): correct StartCursor and EndCursor to reference current page items#17

Merged
josemarluedke merged 1 commit intomainfrom
bug/fix-offset
Dec 29, 2025
Merged

fix(offset): correct StartCursor and EndCursor to reference current page items#17
josemarluedke merged 1 commit intomainfrom
bug/fix-offset

Conversation

@josemarluedke
Copy link
Member

Summary

Fixes a critical bug in offset-based pagination where StartCursor and EndCursor were pointing to incorrect positions, causing pagination to jump to wrong offsets when navigating between pages.

The Problem

  • StartCursor always returned offset 0 (first page of entire dataset)
  • EndCursor returned the offset to the last page of the entire dataset instead of the last item on the current page

This caused pagination to jump incorrectly. For example, with 428 total records and page size 10:

  • First page would return EndCursor pointing to offset 420 (last page)
  • Using that cursor for the second page would jump to offset 420 instead of offset 10
  • Result: skipped 41 pages of data

The Fix

Both cursors now correctly reference items on the current page:

  • StartCursor: Returns cursor of the first item on current page (currentOffset + 1)
  • EndCursor: Returns cursor of the last item on current page, accounting for partial pages at the end
  • Both handle empty result sets properly by returning nil

Changes

  • Updated buildOffsetPageInfo in offset/paginator.go to calculate cursors based on current page position
  • Updated test expectations in offset/paginator_test.go to verify correct cursor behavior
  • Improved documentation to clarify cursor semantics

Test Plan

  • All 10 offset package tests pass
  • All 154 tests pass across entire codebase
  • Integration tests with real PostgreSQL pass
  • Verified cursor values are correct for first, middle, and last pages
  • Verified partial pages (last page with fewer items) return correct EndCursor

🤖 Generated with Claude Code

…age items

Previously, StartCursor always returned offset 0 and EndCursor returned the
offset to the last page of the entire dataset. This caused pagination to
jump incorrectly when using cursors to navigate between pages.

Now both cursors correctly point to items on the current page:
- StartCursor: first item on current page
- EndCursor: last item on current page (accounting for partial pages)

This fixes the issue where requesting a second page would jump to an
incorrect offset (e.g., offset 420 instead of offset 10).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@josemarluedke josemarluedke added the Type: Bug Something isn't working label Dec 29, 2025
@josemarluedke josemarluedke merged commit 07ced34 into main Dec 29, 2025
1 of 2 checks passed
@josemarluedke josemarluedke deleted the bug/fix-offset branch December 29, 2025 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant