* Get unresolved references scoped to specific file paths. * Uses the idx_unresolved_file_path index for efficient lookup.
(filePaths: string[])
| 4720 | * Uses the idx_unresolved_file_path index for efficient lookup. |
| 4721 | */ |
| 4722 | getUnresolvedReferencesByFiles(filePaths: string[]): UnresolvedReference[] { |
| 4723 | if (filePaths.length === 0) return []; |
| 4724 | |
| 4725 | // Chunk under SQLite's parameter limit: the first sync of a very large repo |
| 4726 | // passes every changed file here, which an unbounded `IN (...)` would bind |
| 4727 | // as one parameter each — exceeding MAX_VARIABLE_NUMBER and aborting with |
| 4728 | // "too many SQL variables". (#540) |
| 4729 | const rows: UnresolvedRefRow[] = []; |
| 4730 | for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 4731 | const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 4732 | const placeholders = chunk.map(() => '?').join(','); |
| 4733 | const chunkRows = this.db |
| 4734 | .prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`) |
| 4735 | .all(...chunk) as UnresolvedRefRow[]; |
| 4736 | // Append with a loop, never a spread: the INPUT chunk is bounded, but |
| 4737 | // the RESULT rows per chunk are not — a dense recovery sync (e.g. the |
| 4738 | // #1541 self-heal re-indexing hundreds of files) returns more rows than |
| 4739 | // V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum |
| 4740 | // call stack size exceeded", aborting resolution mid-sync (#1558). |
| 4741 | for (const row of chunkRows) rows.push(row); |
| 4742 | } |
| 4743 | |
| 4744 | return rows.map((row) => ({ |
| 4745 | fromNodeId: row.from_node_id, |
| 4746 | referenceName: row.reference_name, |
| 4747 | referenceKind: row.reference_kind as EdgeKind, |
| 4748 | line: row.line, |
| 4749 | column: row.col, |
| 4750 | candidates: row.candidates ? safeJsonParse(row.candidates, undefined) : undefined, |
| 4751 | filePath: row.file_path, |
| 4752 | language: row.language as Language, |
| 4753 | rowId: row.id, |
| 4754 | })); |
| 4755 | } |
| 4756 | |
| 4757 | /** |
| 4758 | * Delete all unresolved references (after resolution) |
no test coverage detected