feat: persisted query metadata for warm-start consistency#1379
Open
feat: persisted query metadata for warm-start consistency#1379
Conversation
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-browser-wa-sqlite-persisted-collection
@tanstack/db-ivm
@tanstack/db-react-native-sqlite-persisted-collection
@tanstack/db-sqlite-persisted-collection-core
@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: 0 B Total Size: 110 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 4.23 kB ℹ️ View Unchanged
|
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.
Summary
Implements Phase 1 of persisted query metadata to fix a warm-start timing race where rows hydrated from SQLite persistence are incorrectly deleted by disjoint queries.
The bug: When two disjoint queries share a persisted collection (e.g., "history" and "live" message queries), the first query to return can delete rows that belong to the other query's domain. The live query correctly returns
[](no live messages), but the query result handler interprets this as "every unclaimed row should be deleted," wiping out the history rows.The fix (Phase 1): Per-row reference counting with persistence support.
Changes
@tanstack/db— AddedMetadataStorageinterface and optionalmetadataStorageon sync params, so any sync layer can persist metadataquery-db-collection—addRownow tracks new claims and increments a ref count;removeRowonly decrements if the query actually owned the row (returnsfalseif query never loaded it);cleanupQueryInternaluses ref counts consistently; ref counts are loaded from and persisted tometadataStoragedb-sqlite-persisted-collection-core— Addedref_countcolumn on the row data table;loadSubsetreturnsrefCount; addedupdateRefCounts,loadMetadata,storeMetadata,deleteMetadatamethods; addedcollection_metadatatable;createWrappedSyncConfiginjectsmetadataStorageinto sync paramsPhases 2 & 3 (future)
queryToRows/rowToQueriesownership maps so the first query result can properly diff against the previous session's stateSee
rfcs/001-persisted-query-metadata.md(not included in this PR) for the full design.Test plan
🤖 Generated with Claude Code