-
Notifications
You must be signed in to change notification settings - Fork 166
Pass orderBy and limit to lazy collection loadSubset in joins #1243
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
|
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: +363 B (+0.39%) Total Size: 92.4 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
Two changes that work together to solve empty loadSubsetOptions when using syncMode: 'on-demand' with joins: 1. Inner join active/lazy determination now respects orderBy Previously, inner joins always used a size heuristic to pick the active (fully-loaded) vs lazy (join-key-loaded) collection. Since both collections are empty at compile time, the heuristic was arbitrary (right side always won). Now, when the query has an orderBy referencing a specific source, that source becomes active. This means the orderBy collection's queryFn receives orderBy (and limit when present) in loadSubsetOptions, enabling efficient server-side sorting and pagination. The other collection loads matching rows via join keys. 2. Lazy collection's loadSubset receives orderBy/limit from the query When the join tap loads data for the lazy collection, it now passes the query's orderBy and limit (when they reference the lazy collection's fields) to requestSnapshot. This helps sync layers optimize fetching even when the active/lazy choice is fixed by join type (e.g., left join always has right side as lazy). https://claude.ai/code/session_0152XUjMHqomrkmbCcZLJS9D
f019ac2 to
ea23367
Compare
🎯 Changes
This PR enables the sync layer to optimize data fetching for lazy-loaded collections in join queries by passing
orderByandlimitinformation to theloadSubsetmethod.Key Changes:
New
computeOrderByForAliasfunction injoins.ts:orderByandlimitfrom a query when they reference fields belonging to a specific aliasundefinedif orderBy references fields from a different collectionEnhanced join processing:
orderByandlimittorequestSnapshotcalls for lazy-loaded collectionsComprehensive test coverage:
Behavior:
orderBythat references fields from the lazy collection in a join, this information is now passed toloadSubsetorderByreferences fields from the active collection, it is not passed to the lazy collection'sloadSubsetlimitis adjusted to account foroffsetwhen both are present✅ Checklist
pnpm test:pr.🚀 Release Impact
https://claude.ai/code/session_0152XUjMHqomrkmbCcZLJS9D