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

Function canOptimizeInArrayExpression

packages/db/src/utils/index-optimization.ts:790–812  ·  view source on GitHub ↗

* Checks if an IN array expression can be optimized

(expression: BasicExpression, collection: CollectionLike<T, TKey>)

Source from the content-addressed store, hash-verified

788 * Checks if an IN array expression can be optimized
789 */
790function canOptimizeInArrayExpression<
791 T extends object,
792 TKey extends string | number,
793>(expression: BasicExpression, collection: CollectionLike<T, TKey>): boolean {
794 if (expression.type !== `func` || expression.args.length !== 2) {
795 return false
796 }
797
798 const fieldArg = expression.args[0]!
799 const arrayArg = expression.args[1]!
800
801 if (
802 fieldArg.type === `ref` &&
803 arrayArg.type === `val` &&
804 Array.isArray((arrayArg as any).value)
805 ) {
806 const fieldPath = (fieldArg as any).path
807 const index = findIndexForField(collection, fieldPath)
808 return index !== undefined
809 }
810
811 return false
812}

Callers 1

canOptimizeExpressionFunction · 0.85

Calls 1

findIndexForFieldFunction · 0.85

Tested by

no test coverage detected