Defined in: packages/db/src/query/subset-dedupe.ts:34
Deduplicated wrapper for a loadSubset function. Tracks what data has been loaded and avoids redundant calls by applying subset logic to predicates.
The options for the DeduplicatedLoadSubset
The underlying loadSubset function to wrap
An optional callback function that is invoked when a loadSubset call is deduplicated. If the call is deduplicated because the requested data is being loaded by an inflight request, then this callback is invoked when the inflight request completes successfully and the data is fully loaded. This callback is useful if you need to track rows per query, in which case you can't ignore deduplicated calls because you need to know which rows were loaded for each query.
const dedupe = new DeduplicatedLoadSubset({ loadSubset: myLoadSubset, onDeduplicate: (opts) => console.log(`Call was deduplicated:`, opts) })
// First call - fetches data
await dedupe.loadSubset({ where: gt(ref('age'), val(10)) })
// Second call - subset of first, returns true immediately
await dedupe.loadSubset({ where: gt(ref('age'), val(20)) })
// Clear state to start fresh
dedupe.reset()
const dedupe = new DeduplicatedLoadSubset({ loadSubset: myLoadSubset, onDeduplicate: (opts) => console.log(`Call was deduplicated:`, opts) })
// First call - fetches data
await dedupe.loadSubset({ where: gt(ref('age'), val(10)) })
// Second call - subset of first, returns true immediately
await dedupe.loadSubset({ where: gt(ref('age'), val(20)) })
// Clear state to start fresh
dedupe.reset()
new DeduplicatedLoadSubset(opts): DeduplicatedLoadSubset;
new DeduplicatedLoadSubset(opts): DeduplicatedLoadSubset;
Defined in: packages/db/src/query/subset-dedupe.ts:67
(options) => true | Promise<void>
(options) => void
DeduplicatedLoadSubset
loadSubset(options): true | Promise<void>;
loadSubset(options): true | Promise<void>;
Defined in: packages/db/src/query/subset-dedupe.ts:85
Load a subset of data, with automatic deduplication based on previously loaded predicates and in-flight requests.
This method is auto-bound, so it can be safely passed as a callback without losing its this context (e.g., loadSubset: dedupe.loadSubset in a sync config).
The predicate options (where, orderBy, limit)
true | Promise<void>
true if data is already loaded, or a Promise that resolves when data is loaded
reset(): void;
reset(): void;
Defined in: packages/db/src/query/subset-dedupe.ts:198
Reset all tracking state. Clears the history of loaded predicates and in-flight calls. Use this when you want to start fresh, for example after clearing the underlying data store.
Note: Any in-flight requests will still complete, but they will not update the tracking state after the reset. This prevents old requests from repopulating cleared state.
void
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
