Skip to content

feat: cursor pagination for /api/usage#570

Merged
greatest0fallt1me merged 7 commits into
CalloraOrg:mainfrom
helenahelenavanbeek-png:feature/usage-cursor-pagination
Jun 28, 2026
Merged

feat: cursor pagination for /api/usage#570
greatest0fallt1me merged 7 commits into
CalloraOrg:mainfrom
helenahelenavanbeek-png:feature/usage-cursor-pagination

Conversation

@helenahelenavanbeek-png

@helenahelenavanbeek-png helenahelenavanbeek-png commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Closes #406

Description

This PR adds cursor-based pagination to the /api/usage endpoint to replace offset/limit pagination for large data sets.

Changes

  • ✅ Added cursor-based pagination using (created_at, id) keyset
  • ✅ Cursor format: base64 encoded created_at|id
  • ✅ Backwards compatible with existing offset/limit callers
  • ✅ Added validation for malformed cursors (returns 400)
  • ✅ Updated repository interfaces to support cursor
  • ✅ All tests passing (77/77)

Why

Offset/limit pagination degrades performance on tables with millions of records. Cursor pagination using keyset on (created_at, id) provides O(log n) performance even on deep pages.

Testing

  • Unit tests for cursor pagination
  • Validation for malformed cursors
  • Backwards compatibility tests
  • Edge cases (duplicate timestamps, invalid cursors)

Performance

  • Uses index on (created_at DESC, id DESC)
  • O(log n) for deep page access
  • No performance degradation on large datasets

- Add cursor-based pagination to GET /api/usage endpoint
- Support both cursor and offset/limit pagination (backwards compatible)
- Cursor format: base64 encoded 'created_at|id'
- Add validation for malformed cursors (returns 400)
- Use composite index on (created_at DESC, id DESC) for O(log n) performance
- Update repository interfaces to support cursor parameter
- Update InMemoryUsageEventsRepository to handle cursor pagination
- Regenerate error codes and OpenAPI documentation
- All tests passing (77/77)

Closes CalloraOrg#406
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@helenahelenavanbeek-png Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Merged via direct push to main (admin)

@greatest0fallt1me greatest0fallt1me merged commit 776be53 into CalloraOrg:main Jun 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cursor-based pagination to GET /api/usage to replace offset/limit on large windows

3 participants