Skip to content

Add cursor pagination - #861

Merged
greatest0fallt1me merged 3 commits into
Predictify-org:mainfrom
gloskull:Add-cursor-pagination
Jul 29, 2026
Merged

Add cursor pagination#861
greatest0fallt1me merged 3 commits into
Predictify-org:mainfrom
gloskull:Add-cursor-pagination

Conversation

@gloskull

Copy link
Copy Markdown
Contributor

Motivation

  • Implement cursor/keyset pagination for GET /api/users/:address/predictions so large result sets can be streamed efficiently and deterministically.
  • Avoid skipping rows when multiple predictions share the same createdAt timestamp.
  • Validate incoming cursor values to prevent malformed cursors from reaching the service layer.

Description

  • Added strict cursor validation on the route using a regex for the createdAt|id form and preserved limit coercion in src/routes/users.ts with zod parsing.
  • Implemented stable keyset pagination in src/services/userService.ts by splitting the cursor into createdAt and id and applying WHERE (createdAt < cursorTime) OR (createdAt = cursorTime AND id < cursorId) to match the ORDER BY createdAt DESC, id DESC ordering.
  • Continued returning nextCursor as an ISO timestamp plus prediction id (<createdAt.toISOString()>|<id>) from the last item on the page.
  • Added focused tests in tests/users.test.ts that seed deterministic createdAt values and IDs, assert pagination across tied timestamps does not skip rows, and verify malformed cursors are rejected.

Testing

  • Ran npx eslint src/routes/users.ts src/services/userService.ts which passed for the modified files.
  • Ran npm test -- --runInBand tests/users.test.ts which could not complete due to unavailable local services (Postgres/Redis connection refused), so tests were not executed successfully in this environment.
  • Ran npm run lint and npm run build which failed due to pre-existing lint/type errors outside the scope of these changes; these failures are unrelated to the cursor pagination logic.

Closes #209

@greatest0fallt1me
greatest0fallt1me merged commit 201a9e3 into Predictify-org:main Jul 29, 2026
1 check passed
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 pagination on /api/users/:addr/predictions

2 participants