Pass orderBy and limit to lazy collection loadSubset in joins#1243
Draft
KyleAMathews wants to merge 1 commit intomainfrom
Draft
Pass orderBy and limit to lazy collection loadSubset in joins#1243KyleAMathews wants to merge 1 commit intomainfrom
KyleAMathews wants to merge 1 commit intomainfrom
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: |
Contributor
|
Size Change: +363 B (+0.39%) Total Size: 92.4 kB
ℹ️ View Unchanged
|
Contributor
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 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