Skip to content

fix: cursor pagination for vault transactions endpoint - #1502

Open
Fang0067 wants to merge 1 commit into
Junirezz:mainfrom
Fang0067:fix/issue-1444-cursor-pagination-for-get-vaults-id
Open

Fang0067 wants to merge 1 commit into
Junirezz:mainfrom
Fang0067:fix/issue-1444-cursor-pagination-for-get-vaults-id

Conversation

@Fang0067

Copy link
Copy Markdown

Overview

This PR fixes offset-based pagination on GET /vaults/:id/transactions, which could skip or duplicate rows when new transactions are inserted between page fetches. It adds cursor-based pagination using ?cursor=<timestamp>_<id>, keeps ?page for backward compatibility (deprecated), and exposes a nextCursor field in the response.

Related Issue

Changes

📄 Cursor Pagination

  • [MODIFY] backend/src/pagination.ts

    • Added cursor encode/decode helpers (<timestamp>_<id>).
    • Added cursor-based where clause using (timestamp, id) < cursor with orderBy: [{ timestamp: 'desc' }, { id: 'desc' }].
    • Kept existing offset (?page) logic intact for backward compatibility and marked it deprecated.
  • [MODIFY] backend/src/routes/transactions.ts

    • Accept ?cursor on GET /vaults/:id/transactions; prefer cursor over ?page when both are present.
    • Return nextCursor in the response payload.
  • [MODIFY] backend/openapi.json

    • Documented cursor query parameter as the preferred pagination method.
    • Marked page as deprecated.
    • Added nextCursor to the response schema.
  • [MODIFY] backend/schema-snapshots/get-_api_v1_transactions.json

    • Updated snapshot to include the nextCursor field.

🧪 Tests

  • [ADD] backend/src/__tests__/pagination.test.ts

    • Unit coverage for cursor encode/decode and cursor where/orderBy construction.
  • [MODIFY] backend/src/__tests__/transactions.test.ts

    • Inserts 3 txs, fetches page 1 (limit 2), inserts a new tx, then fetches page 2 via cursor and asserts no skipped or duplicated rows.

Verification Results

npm test -- backend/src/__tests__/pagination.test.ts backend/src/__tests__/transactions.test.ts
✅ pagination.test.ts passed
✅ transactions.test.ts passed (cursor pagination: no skip/duplicate after insert)
Acceptance Criteria Status
Add cursor pagination: support ?cursor=<timestamp>_<id> with where: { (timestamp, id) < cursor } and orderBy: [{timestamp: 'desc'}, {id: 'desc'}] ✅ Implemented in pagination.ts and wired into the transactions route
Keep ?page for backward compat but deprecate and document cursor as preferred ✅ ?page still works; marked deprecated in openapi.json; cursor documented as preferred
Test: insert 3 txs, fetch page 1 (limit 2), insert new tx, fetch page 2 via cursor and assert no skip/duplicate ✅ Covered in transactions.test.ts
Snapshot includes nextCursor field ✅ Updated get-_api_v1_transactions.json and response schema

Closes #1444

@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

@Fang0067 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

This branch has not been deployed

No deployments
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.

Cursor pagination for GET /vaults/:id/transactions uses offset and skips rows when new tx inserted

1 participant