MCPcopy Create free account
hub / github.com/TanStack/db / cleanup

Function cleanup

packages/query-db-collection/src/query.ts:1648–1675  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1646 })
1647
1648 const cleanup = async () => {
1649 unsubscribeFromCollectionEvents()
1650 unsubscribeFromQueries()
1651 persistedRetentionTimers.forEach((timer) => {
1652 clearTimeout(timer)
1653 })
1654 persistedRetentionTimers.clear()
1655
1656 const allQueryKeys = [...hashToQueryKey.values()]
1657 const allHashedKeys = [...state.observers.keys()]
1658
1659 // Force cleanup all queries (explicit cleanup path)
1660 // This ignores hasListeners and always cleans up
1661 for (const hashedKey of allHashedKeys) {
1662 forceCleanupQuery(hashedKey)
1663 }
1664
1665 // Unsubscribe from cache events (cleanup already happened above)
1666 unsubscribeQueryCache()
1667
1668 // Remove queries from TanStack Query cache
1669 await Promise.all(
1670 allQueryKeys.map(async (qKey) => {
1671 await queryClient.cancelQueries({ queryKey: qKey, exact: true })
1672 queryClient.removeQueries({ queryKey: qKey, exact: true })
1673 }),
1674 )
1675 }
1676
1677 /**
1678 * Unload a query subset - the subscription-based cleanup path (on-demand mode).

Callers

nothing calls this directly

Calls 7

unsubscribeFromQueriesFunction · 0.85
forceCleanupQueryFunction · 0.85
forEachMethod · 0.45
clearMethod · 0.45
valuesMethod · 0.45
keysMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected