* Get unresolved references scoped to specific file paths. * Uses the idx_unresolved_file_path index for efficient lookup.
(filePaths: string[])
| 2424 | * Uses the idx_unresolved_file_path index for efficient lookup. |
| 2425 | */ |
| 2426 | getUnresolvedReferencesByFiles(filePaths: string[]): UnresolvedReference[] { |
| 2427 | if (filePaths.length === 0) return []; |
| 2428 | |
| 2429 | // Chunk under SQLite's parameter limit: the first sync of a very large repo |
| 2430 | // passes every changed file here, which an unbounded `IN (...)` would bind |
| 2431 | // as one parameter each — exceeding MAX_VARIABLE_NUMBER and aborting with |
| 2432 | // "too many SQL variables". (#540) |
| 2433 | const rows: UnresolvedRefRow[] = []; |
| 2434 | for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 2435 | const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 2436 | const placeholders = chunk.map(() => '?').join(','); |
| 2437 | const chunkRows = this.db |
| 2438 | .prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`) |
| 2439 | .all(...chunk) as UnresolvedRefRow[]; |
| 2440 | // Append with a loop, never a spread: the INPUT chunk is bounded, but |
| 2441 | // the RESULT rows per chunk are not — a dense recovery sync (e.g. the |
| 2442 | // #1541 self-heal re-indexing hundreds of files) returns more rows than |
| 2443 | // V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum |
| 2444 | // call stack size exceeded", aborting resolution mid-sync (#1558). |
| 2445 | for (const row of chunkRows) rows.push(row); |
| 2446 | } |
| 2447 | |
| 2448 | return rows.map((row) => ({ |
| 2449 | fromNodeId: row.from_node_id, |
| 2450 | referenceName: row.reference_name, |
| 2451 | referenceKind: row.reference_kind as EdgeKind, |
| 2452 | line: row.line, |
| 2453 | column: row.col, |
| 2454 | candidates: row.candidates ? safeJsonParse(row.candidates, undefined) : undefined, |
| 2455 | filePath: row.file_path, |
| 2456 | language: row.language as Language, |
| 2457 | rowId: row.id, |
| 2458 | })); |
| 2459 | } |
| 2460 | |
| 2461 | /** |
| 2462 | * Delete all unresolved references (after resolution) |
no test coverage detected