* Resolution edges leaving a `language` node whose TARGET is in one of * `targetFiles`, or whose SOURCE is under one of `sourceDirs` — the narrow * re-resolution set when modules or packages appear or vanish below an * unchanged set of Python roots.
(
language: Language,
targetFiles: string[],
sourceDirs: string[],
importNodeSegments: string[] = []
)
| 5378 | * unchanged set of Python roots. |
| 5379 | */ |
| 5380 | getResolutionEdgesTouchingFiles( |
| 5381 | language: Language, |
| 5382 | targetFiles: string[], |
| 5383 | sourceDirs: string[], |
| 5384 | importNodeSegments: string[] = [] |
| 5385 | ): Array<Edge & { edgeId: number; sourceFilePath: string; sourceLanguage: Language }> { |
| 5386 | // Collect candidate edge ids through narrow indexed lookups, then load |
| 5387 | // the full rows edge-first (CROSS JOIN pins the join order; left to |
| 5388 | // itself the planner drove the query from the language index and one |
| 5389 | // rename took 18 s). |
| 5390 | const candidates = new Set<number>(); |
| 5391 | const idsWhere = (column: 'source' | 'target', nodeIds: string[]): void => { |
| 5392 | for (let i = 0; i < nodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5393 | const chunk = nodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5394 | const rows = this.db |
| 5395 | .prepare(`SELECT id FROM edges WHERE ${column} IN (${chunk.map(() => '?').join(',')})`) |
| 5396 | .all(...chunk) as Array<{ id: number }>; |
| 5397 | for (const r of rows) candidates.add(r.id); |
| 5398 | } |
| 5399 | }; |
| 5400 | // Edges into the affected module files. |
| 5401 | for (let i = 0; i < targetFiles.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5402 | const chunk = targetFiles.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5403 | const nodes = this.db |
| 5404 | .prepare(`SELECT id FROM nodes WHERE file_path IN (${chunk.map(() => '?').join(',')})`) |
| 5405 | .all(...chunk) as Array<{ id: string }>; |
| 5406 | idsWhere('target', nodes.map((n) => n.id)); |
| 5407 | } |
| 5408 | // Edges out of a changed package: its nodes by an index range on the |
| 5409 | // path (`dir/` up to `dir0`, the character after '/'). |
| 5410 | for (const dir of sourceDirs) { |
| 5411 | const nodes = (dir === '' |
| 5412 | ? this.db.prepare('SELECT id FROM nodes WHERE language = ?').all(language) |
| 5413 | : this.db |
| 5414 | .prepare('SELECT id FROM nodes WHERE file_path >= ? AND file_path < ?') |
| 5415 | .all(`${dir}/`, `${dir}0`)) as Array<{ id: string }>; |
| 5416 | idsWhere('source', nodes.map((n) => n.id)); |
| 5417 | } |
| 5418 | // Imports the resolver couldn't place and bound to their own `import` |
| 5419 | // node rather than parking as a failure, matched by the module name they |
| 5420 | // spell: ONE read of the language's import nodes, filtered here. (A LIKE |
| 5421 | // scan of the edges per name measured ~225 ms each on django's 213k.) |
| 5422 | if (importNodeSegments.length > 0) { |
| 5423 | const wanted = new Set(importNodeSegments); |
| 5424 | const nodes = this.db |
| 5425 | .prepare("SELECT id, name FROM nodes WHERE kind = 'import' AND language = ?") |
| 5426 | .all(language) as Array<{ id: string; name: string }>; |
| 5427 | idsWhere('target', nodes.filter((n) => n.name.split('.').some((seg) => wanted.has(seg))).map((n) => n.id)); |
| 5428 | } |
| 5429 | return this.loadResolutionEdges(language, [...candidates]); |
| 5430 | } |
| 5431 | |
| 5432 | /** |
| 5433 | * Resolution edges leaving any node of `files` — the candidates when an |
no test coverage detected