* 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[] = []
)
| 5489 | * unchanged set of Python roots. |
| 5490 | */ |
| 5491 | getResolutionEdgesTouchingFiles( |
| 5492 | language: Language, |
| 5493 | targetFiles: string[], |
| 5494 | sourceDirs: string[], |
| 5495 | importNodeSegments: string[] = [] |
| 5496 | ): Array<Edge & { edgeId: number; sourceFilePath: string; sourceLanguage: Language }> { |
| 5497 | // Collect candidate edge ids through narrow indexed lookups, then load |
| 5498 | // the full rows edge-first (CROSS JOIN pins the join order; left to |
| 5499 | // itself the planner drove the query from the language index and one |
| 5500 | // rename took 18 s). |
| 5501 | const candidates = new Set<number>(); |
| 5502 | const idsWhere = (column: 'source' | 'target', nodeIds: string[]): void => { |
| 5503 | for (let i = 0; i < nodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5504 | const chunk = nodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5505 | const rows = this.db |
| 5506 | .prepare(`SELECT id FROM edges WHERE ${column} IN (${chunk.map(() => '?').join(',')})`) |
| 5507 | .all(...chunk) as Array<{ id: number }>; |
| 5508 | for (const r of rows) candidates.add(r.id); |
| 5509 | } |
| 5510 | }; |
| 5511 | // Edges into the affected module files. |
| 5512 | for (let i = 0; i < targetFiles.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5513 | const chunk = targetFiles.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5514 | const nodes = this.db |
| 5515 | .prepare(`SELECT id FROM nodes WHERE file_path IN (${chunk.map(() => '?').join(',')})`) |
| 5516 | .all(...chunk) as Array<{ id: string }>; |
| 5517 | idsWhere('target', nodes.map((n) => n.id)); |
| 5518 | } |
| 5519 | // Edges out of a changed package: its nodes by an index range on the |
| 5520 | // path (`dir/` up to `dir0`, the character after '/'). |
| 5521 | for (const dir of sourceDirs) { |
| 5522 | const nodes = (dir === '' |
| 5523 | ? this.db.prepare('SELECT id FROM nodes WHERE language = ?').all(language) |
| 5524 | : this.db |
| 5525 | .prepare('SELECT id FROM nodes WHERE file_path >= ? AND file_path < ?') |
| 5526 | .all(`${dir}/`, `${dir}0`)) as Array<{ id: string }>; |
| 5527 | idsWhere('source', nodes.map((n) => n.id)); |
| 5528 | } |
| 5529 | // Imports the resolver couldn't place and bound to their own `import` |
| 5530 | // node rather than parking as a failure, matched by the module name they |
| 5531 | // spell: ONE read of the language's import nodes, filtered here. (A LIKE |
| 5532 | // scan of the edges per name measured ~225 ms each on django's 213k.) |
| 5533 | if (importNodeSegments.length > 0) { |
| 5534 | const wanted = new Set(importNodeSegments); |
| 5535 | const nodes = this.db |
| 5536 | .prepare("SELECT id, name FROM nodes WHERE kind = 'import' AND language = ?") |
| 5537 | .all(language) as Array<{ id: string; name: string }>; |
| 5538 | idsWhere('target', nodes.filter((n) => n.name.split('.').some((seg) => wanted.has(seg))).map((n) => n.id)); |
| 5539 | } |
| 5540 | return this.loadResolutionEdges(language, [...candidates]); |
| 5541 | } |
| 5542 | |
| 5543 | /** |
| 5544 | * Resolution edges leaving any node of `files` — the candidates when an |
no test coverage detected