MCPcopy Create free account
hub / github.com/codemix/graph / extractRemainingCondition

Function extractRemainingCondition

packages/graph/src/indexes/QueryPlanner.ts:259–294  ·  view source on GitHub ↗
(
  condition: Condition,
  usedHint: IndexHint,
)

Source from the content-addressed store, hash-verified

257 * @returns Remaining condition to filter, or undefined if fully covered.
258 */
259export function extractRemainingCondition(
260 condition: Condition,
261 usedHint: IndexHint,
262): Condition | undefined {
263 const [operator] = condition;
264
265 // If this is the exact condition being handled by index
266 if (isConditionFullyCovered(condition, usedHint)) {
267 return undefined;
268 }
269
270 // For AND conditions, remove the covered sub-condition
271 if (operator === "and") {
272 const remaining: Condition[] = [];
273
274 for (let i = 1; i < condition.length; i++) {
275 const subCondition = condition[i] as Condition;
276 if (subCondition !== usedHint.condition) {
277 remaining.push(subCondition);
278 }
279 }
280
281 if (remaining.length === 0) {
282 return undefined;
283 }
284
285 if (remaining.length === 1) {
286 return remaining[0];
287 }
288
289 return ["and", ...remaining] as Condition;
290 }
291
292 // For other conditions, we need to keep the whole thing
293 return condition;
294}

Callers 1

#tryIndexLookupMethod · 0.85

Calls 2

isConditionFullyCoveredFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected