Skip to content
Source
Sign inSign up
TanStack/db

refactor(query-db-collection): extract query ownership helpers #1664

MergedKyleAMathews(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/1664/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Showing 2 changed files with 59 additions and 45 deletions.

x
0 of 2 viewed, 2 left
5 additions and 0 deletions.changeset/extract-query-ownership-helpers.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-db-collection': patch
+---
+​
+Extract internal query row ownership helpers to make lifecycle cleanup paths easier to reason about while preserving existing behavior.
54 additions and 45 deletionspackages/query-db-collection/src/query.tsModified
View file
@@ -697,30 +697,60 @@
// 3. Decrements refcount and GCs rows where count reaches 0
const queryRefCounts = new Map<string, number>()
​
- // Helper function to add a row to the internal state
- const addRow = (rowKey: string | number, hashedQueryKey: string) => {
- const rowToQueriesSet = rowToQueries.get(rowKey) || new Set()
- rowToQueriesSet.add(hashedQueryKey)
- rowToQueries.set(rowKey, rowToQueriesSet)
+ const addRowOwner = (rowKey: string | number, hashedQueryKey: string) => {
+ const owners = rowToQueries.get(rowKey) || new Set<string>()
+ owners.add(hashedQueryKey)
+ rowToQueries.set(rowKey, owners)
​
- const queryToRowsSet = queryToRows.get(hashedQueryKey) || new Set()
- queryToRowsSet.add(rowKey)
- queryToRows.set(hashedQueryKey, queryToRowsSet)