-
Notifications
You must be signed in to change notification settings - Fork 131
feat(db,electric,query): separate cursor expressions for flexible pagination #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: cc8fccb The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +231 B (+0.26%) Total Size: 88.4 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.35 kB ℹ️ View Unchanged
|
6d0a91a to
f1a6d36
Compare
7f03f25 to
e5dc9f7
Compare
…e in loadSubset - Add CursorExpressions type with whereFrom, whereCurrent, and lastKey - LoadSubsetOptions.where no longer includes cursor - passed separately via cursor property - Add offset to LoadSubsetOptions for offset-based pagination support - Electric sync layer makes two parallel requestSnapshot calls when cursor present - Query collection serialization includes offset for query key generation This allows sync layers to choose between cursor-based or offset-based pagination, and Electric can efficiently handle tie-breaking with targeted requests. test(react-db): update useLiveInfiniteQuery test mock to handle cursor expressions The test mock's loadSubset handler now handles the new cursor property in LoadSubsetOptions by combining whereCurrent (ties) and whereFrom (next page) data, deduplicating by id, and re-sorting. fix(electric): make cursor requestSnapshot calls sequential Changed parallel requestSnapshot calls to sequential to avoid potential issues with concurrent snapshot requests that may cause timeouts in CI. fix(electric): combine cursor expressions into single requestSnapshot Instead of making two separate requestSnapshot calls (one for whereFrom, one for whereCurrent), combine them using OR into a single request. This avoids potential issues with multiple sequential snapshot requests that were causing timeouts in CI. The combined expression (whereFrom OR whereCurrent) matches the original behavior where cursor was combined with the where clause. wip working? update changeset fix query test
ff54e90 to
091f214
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Excited to play around with all the improvements in saaslarge next week!
"when cursor is present" — this is used a number of places and it doesn't seem clear when/how this would happen? Is this just for infinite scroll type scenarios?
| .limit(10), | ||
| ) | ||
|
|
||
| console.log(`[QUERY DEBUG] query:`, query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logging
Summary
This PR enhances
LoadSubsetOptionswith separate cursor expressions and offset support, allowing sync layers to choose between cursor-based or offset-based pagination strategies.API Changes:
CursorExpressionstype withwhereFrom,whereCurrent, and optionallastKeypropertiesLoadSubsetOptions.whereno longer includes cursor expressions - these are now passed separately viacursoroffsettoLoadSubsetOptionsfor offset-based pagination supportrequestSnapshotcalls when cursor is present:whereCurrent(all ties at boundary, no limit)whereFrom(rows after cursor, with limit)offsetfor query key generationtruncateevent to collections, emitted when synced data is truncated (e.g., aftermust-refetch)Bug Fixes:
setWindowpagination: cursor expressions are now correctly built when paging through multi-column orderBy resultsloadNextItemsnow passes the correct window offset to prevent incorrect deduplicationCollectionSubscribernow listens fortruncateevents to reset cursor tracking state, preventing stale cursor data aftermust-refetchBenefits
where) and pagination (cursor/offset)setWindowcorrectly triggers backend loading for subsequent pages in multi-column orderBy queriesStacked PR
This PR is stacked on #926 (
samwillis/order-by-improvments)Test plan
setWindow