Open History to see the last commit
1---
2id: DeduplicatedLoadSubset
3title: DeduplicatedLoadSubset
4---
5
6# Class: DeduplicatedLoadSubset
7
8Defined in: [packages/db/src/query/subset-dedupe.ts:48](https://github.com/TanStack/db/blob/main/packages/db/src/query/subset-dedupe.ts#L48)
9
10Deduplicated wrapper for a loadSubset function.
11Tracks what data has been loaded and avoids redundant calls by applying
12subset logic to predicates.
13
14## Param
15
16The options for the DeduplicatedLoadSubset
17
18## Param
19
20The underlying loadSubset function to wrap
21
22## Param
23
24An optional callback function that is invoked when a loadSubset call is deduplicated.
25 If the call is deduplicated because the requested data is being loaded by an inflight request,
26 then this callback is invoked when the inflight request completes successfully and the data is fully loaded.
27 This callback is useful if you need to track rows per query, in which case you can't ignore deduplicated calls
28 because you need to know which rows were loaded for each query.
29
30## Example
31
32```ts
33const dedupe = new DeduplicatedLoadSubset({ loadSubset: myLoadSubset, onDeduplicate: (opts) => console.log(`Call was deduplicated:`, opts) })
34
35// First call - fetches data
36await dedupe.loadSubset({ where: gt(ref('age'), val(10)) })
37
38// Second call - subset of first, returns true immediately
39await dedupe.loadSubset({ where: gt(ref('age'), val(20)) })
40
41// Clear state to start fresh
42dedupe.reset()
43```
44
45## Constructors
46
47### Constructor
48
49```ts
50new DeduplicatedLoadSubset(opts): DeduplicatedLoadSubset;
51```
52
53Defined in: [packages/db/src/query/subset-dedupe.ts:78](https://github.com/TanStack/db/blob/main/packages/db/src/query/subset-dedupe.ts#L78)
54
55#### Parameters
56
57##### opts
58
59###### loadSubset
60
61(`options`) => `true` \| `Promise`\<`void`\>
62
63###### onDeduplicate?
64
65(`options`) => `void`
66
67#### Returns
68
69`DeduplicatedLoadSubset`
70
71## Methods
72
73### loadSubset()
74
75```ts
76loadSubset(options): true | Promise<void>;
77```
78
79Defined in: [packages/db/src/query/subset-dedupe.ts:96](https://github.com/TanStack/db/blob/main/packages/db/src/query/subset-dedupe.ts#L96)
80
81Load a subset of data, with automatic deduplication based on previously
82loaded predicates and in-flight requests.
83
84This method is auto-bound, so it can be safely passed as a callback without
85losing its `this` context (e.g., `loadSubset: dedupe.loadSubset` in a sync config).
86
87#### Parameters
88
89##### options
90
91[`LoadSubsetOptions`](../type-aliases/LoadSubsetOptions.md)
92
93The predicate options (where, orderBy, limit)
94
95#### Returns
96
97`true` \| `Promise`\<`void`\>
98
99true if data is already loaded, or a Promise that resolves when data is loaded
100
101***
102
103### reset()
104
105```ts
106reset(): void;
107```
108
109Defined in: [packages/db/src/query/subset-dedupe.ts:227](https://github.com/TanStack/db/blob/main/packages/db/src/query/subset-dedupe.ts#L227)
110
111Reset all tracking state.
112Clears the history of loaded predicates and in-flight calls.
113Use this when you want to start fresh, for example after clearing the underlying data store.
114
115Note: Any in-flight requests will still complete, but they will not update the tracking
116state after the reset. This prevents old requests from repopulating cleared state.
117
118#### Returns
119
120`void`