refactor(query-db-collection): extract query ownership helpers#1664
refactor(query-db-collection): extract query ownership helpers#1664KyleAMathews wants to merge 2 commits into
Conversation
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
📝 WalkthroughWalkthroughInternal query row ownership tracking is refactored into explicit helpers. Baseline hydration, placeholder cleanup, result reconciliation, and query cleanup now use these helpers without changing public APIs. ChangesQuery ownership lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Size Change: 0 B Total Size: 125 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 4.22 kB ℹ️ View Unchanged
|
kevin-dp
left a comment
There was a problem hiding this comment.
Should we rename removeQueryOwnership to removeQueryOwners in order to be consistent with addRowOwners naming?
Extracts the internal row/query ownership bookkeeping in
@tanstack/query-db-collectioninto small private helpers. There is no intended public API or user-visible behavior change; this is lifecycle groundwork for future cancellation/lease-manager work.Related
Approach
This keeps the existing maps and lifecycle flow intact while centralizing the direct mutations of query ownership state:
addRowOwnerupdatesrowToQueriesandqueryToRowsfor one query/row relationship.addRowOwnershydrates ownership for persisted rows with multiple owners.removeRowOwnerremoves one query/row relationship while preserving existing empty-set behavior.removeQueryOwnershipcomputes the remaining owners for all rows associated with a query during cleanup.The extraction is intentionally local to
query.tsand does not change observer refcounting, invalidation handling, or persisted retention semantics.Key invariants
rowToQueriesandqueryToRowsremain inverse ownership indexes.Non-goals
Trade-offs
A full lease manager would make lifecycle ownership more explicit, but would be higher risk. This PR takes a smaller step: it reduces duplicated map mutation code and creates clearer seams for future work while preserving current behavior.
Verification
Files changed
packages/query-db-collection/src/query.ts— extracts private row/query ownership helpers and routes existing ownership call sites through them..changeset/extract-query-ownership-helpers.md— patch changeset for the internal refactor.Summary by CodeRabbit
Bug Fixes
Release
@tanstack/query-db-collection.