MCPcopy Index your code
hub / github.com/TanStack/db / loadNextItems

Method loadNextItems

packages/db/src/query/effect.ts:901–934  ·  view source on GitHub ↗

* Load n more items from the source collection, starting from the cursor * position (the biggest value sent so far).

(orderByInfo: OrderByOptimizationInfo, n: number)

Source from the content-addressed store, hash-verified

899 * position (the biggest value sent so far).
900 */
901 private loadNextItems(orderByInfo: OrderByOptimizationInfo, n: number): void {
902 const { alias } = orderByInfo
903 const subscription = this.subscriptions[alias]
904 if (!subscription) return
905
906 const cursor = computeOrderedLoadCursor(
907 orderByInfo,
908 this.biggestSentValue.get(alias),
909 this.lastLoadRequestKey.get(alias),
910 alias,
911 n,
912 )
913 if (!cursor) return // Duplicate request — skip
914
915 this.lastLoadRequestKey.set(alias, cursor.loadRequestKey)
916
917 subscription.requestLimitedSnapshot({
918 orderBy: cursor.normalizedOrderBy,
919 limit: n,
920 minValues: cursor.minValues,
921 trackLoadSubsetPromise: false,
922 onLoadSubsetResult: (loadResult: Promise<void> | true) => {
923 // Track in-flight load to prevent redundant concurrent requests
924 if (loadResult instanceof Promise) {
925 this.pendingOrderedLoadPromise = loadResult
926 loadResult.finally(() => {
927 if (this.pendingOrderedLoadPromise === loadResult) {
928 this.pendingOrderedLoadPromise = undefined
929 }
930 })
931 }
932 },
933 })
934 }
935
936 /**
937 * Track the biggest value sent for a given ordered alias.

Callers 1

loadMoreIfNeededMethod · 0.95

Calls 4

computeOrderedLoadCursorFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected