Skip to content

feat(api): implement B-Tree keyset cursor pagination and atomic merge…#11

Merged
jonathanmagambo merged 1 commit into
mainfrom
feat/pagination
Mar 8, 2026
Merged

feat(api): implement B-Tree keyset cursor pagination and atomic merge…#11
jonathanmagambo merged 1 commit into
mainfrom
feat/pagination

Conversation

@jonathanmagambo
Copy link
Copy Markdown
Collaborator

PR: Cursor-Based Pagination (B-Tree Keyset)

Component: crates/storage, crates/server, crates/types

Branch: feat/pagination

Summary

Implements performant, cursor-based pagination (keyset pagination) across the document API. This replaces simple "list all" behavior, allowing ForgeDB to handle massive collections without memory exhaustion or high latency.

Key Changes

  • Storage Engine Integration: Added list_paginated to the redbx StorageEngine, leveraging B-Tree keyset traversal to start scans after a specific ID without skipping rows.
  • Pagination Envelope: Standardized all list responses to return a PaginatedResponse containing data: Vec<T>, next_cursor: Option<String>, and has_more: bool.
  • API Defaults:
    • Default limit: 50.
    • Max limit: 1000 (enforced via PaginationParams::resolved_limit).
  • Performance: Pagination cursors are O(log N) to find the starting point, making deep paging just as fast as the first page.

Technical Details

We use "Exclusive Cursors". The cursor passed in the query string is the ID of the last document seen; the storage engine initiates the scan from the next available key in the COW B-tree.

… patch updates

- Added `PaginationParams` and `PaginatedResponse` envelope types to `forge-types`
- Replaced naïve enumeration indexing in `list_paginated` with true `std::ops::Bound::Excluded` keyset range queries for maximum MVCC read performance in `forge-storage`
- Implemented `update_doc` exposing an atomic read-modify-write block
- Wired `PaginationParams` into `GET /v1/:collection` endpoint handling
- Added `PATCH /v1/:collection/:id` endpoint implementing RFC 7396 JSON Merge Patch
- Resolved clippy type complexity warnings via `PaginatedList` type alias
- Included suite of integration tests covering bounds conditions and null-value patching
@jonathanmagambo jonathanmagambo merged commit c1e2bb1 into main Mar 8, 2026
2 checks passed
@jonathanmagambo jonathanmagambo deleted the feat/pagination branch March 8, 2026 01:55
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.

1 participant