Skip to content

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

Description

@greatest0fallt1me

Description

GET /api/usage uses offset/limit and degrades on developers with millions of events. Add cursor pagination keyed on (created_at, id) so deep paging stays O(log n) on the index.

Requirements and Context

  • Extend parsePagination in src/lib/pagination.ts with a cursor branch
  • usageEventsRepository.pg.ts adds a keyset query path
  • Backwards-compatible with current limit/offset callers
  • Must be secure, tested, and documented
  • Should be efficient and easy to review

Suggested Execution

  1. Fork the repo and create a branch
    git checkout -b feature/usage-cursor-pagination
  2. Implement changes
    • src/lib/pagination.ts
    • src/repositories/usageEventsRepository.pg.ts
    • src/routes/usage.ts
  3. Test and commit
    • npm test -- usage
    • Cover edge cases (malformed cursor, duplicate timestamps)
    • Include test output and notes in the PR

Example commit message

feat: cursor pagination for /api/usage

Acceptance Criteria

  • Cursor encodes created_at+id
  • Tampered cursor returns 400
  • EXPLAIN shows index keyset
  • OpenAPI updated

Guidelines

  • Backend (Node/TS): Jest, minimum 90% coverage
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Labels

GRANTFOX OSSGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignOFFICIAL CAMPAIGNOfficial GrantFox campaign issueStellar WaveIssues in the Stellar wave programapiAPI endpoint/contract workbackendBackend service workperformancePerformance/efficiency

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions