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
- Fork the repo and create a branch
git checkout -b feature/usage-cursor-pagination
- Implement changes
src/lib/pagination.ts
src/repositories/usageEventsRepository.pg.ts
src/routes/usage.ts
- 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
Guidelines
- Backend (Node/TS): Jest, minimum 90% coverage
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
GET /api/usageuses 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
parsePaginationinsrc/lib/pagination.tswith a cursor branchusageEventsRepository.pg.tsadds a keyset query pathlimit/offsetcallersSuggested Execution
src/lib/pagination.tssrc/repositories/usageEventsRepository.pg.tssrc/routes/usage.tsnpm test -- usageExample commit message
Acceptance Criteria
created_at+idGuidelines