-
Notifications
You must be signed in to change notification settings - Fork 116
Auto append to static queryKey when in on-demand mode for Query Collection #800
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?
Auto append to static queryKey when in on-demand mode for Query Collection #800
Conversation
… mode When using a static queryKey with syncMode: 'on-demand', the system now automatically appends serialized LoadSubsetOptions to create unique cache keys for different predicate combinations. This fixes an issue where static queryKeys in on-demand mode would cause all live queries with different predicates to share the same cache entry, defeating the purpose of predicate push-down. Changes: - Added serialization utilities for LoadSubsetOptions (serializeLoadSubsetOptions, serializeExpression, serializeValue) - Modified createQueryFromOpts to automatically append serialized predicates when queryKey is static and syncMode is 'on-demand' - Function-based queryKeys continue to work as before - Eager mode with static queryKeys unchanged (no automatic serialization) Tests: - Added comprehensive test suite for static queryKey with on-demand mode - Tests verify different predicates create separate cache entries - Tests verify identical predicates reuse the same cache entry - Tests verify eager mode behavior unchanged - All existing tests pass
🦋 Changeset detectedLatest commit: 41d5a86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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: 0 B Total Size: 86 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
kevin-dp
left a comment
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.
Left some comments.
| * Serializes LoadSubsetOptions into a stable, hashable format for query keys | ||
| * @internal | ||
| */ | ||
| function serializeLoadSubsetOptions( |
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.
Let's move all the serialization functions into a utility file
| result.orderBy = options.orderBy.map((clause) => ({ | ||
| expression: serializeExpression(clause.expression), | ||
| direction: clause.compareOptions.direction, | ||
| nulls: clause.compareOptions.nulls, |
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.
This object only contains the direction and nulls but is missing the other options from StringCollationConfig:
export type CompareOptions = StringCollationConfig & {
direction: OrderByDirection
nulls: `first` | `last`
}| */ | ||
| function serializeLoadSubsetOptions( | ||
| options: LoadSubsetOptions | undefined | ||
| ): unknown { |
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.
Why is the return type typed as unknown ? Shouldn't this be string | null.
Actually, i'm wondering why we return null instead of undefined. I think the code would be slightly simplier if we return undefined. So the return type would be string | undefined`.
When using a static queryKey with syncMode: 'on-demand', the system now automatically appends serialized LoadSubsetOptions to create unique cache keys for different predicate combinations.
This fixes an issue where static queryKeys in on-demand mode would cause all live queries with different predicates to share the same cache entry, defeating the purpose of predicate push-down.
Changes:
Tests:
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact