* Resolution edges whose TARGET symbol is named one of `names` — the edges a * sync must re-resolve after `names` gained or lost a definition (CG-33). * * Resolution binds a reference to a node whose name matches the reference's * tail, and it picks among ALL same-named definitions proje
(
names: string[],
perNameCeiling: number = 500,
countedUpToEdgeId?: number
)
| 5357 | * that stays below it. |
| 5358 | */ |
| 5359 | getResolutionEdgesByTargetName( |
| 5360 | names: string[], |
| 5361 | perNameCeiling: number = 500, |
| 5362 | countedUpToEdgeId?: number |
| 5363 | ): Array<Edge & { edgeId: number; sourceFilePath: string; sourceLanguage: Language }> { |
| 5364 | if (names.length === 0) return []; |
| 5365 | |
| 5366 | // Pass 1: per-name edge counts, chunked under the SQLite parameter limit. |
| 5367 | const keep: string[] = []; |
| 5368 | const counted = countedUpToEdgeId === undefined ? '' : 'AND e.id <= ?'; |
| 5369 | for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5370 | const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5371 | const placeholders = chunk.map(() => '?').join(','); |
| 5372 | const counts = this.db |
| 5373 | .prepare( |
| 5374 | `SELECT tgt.name AS name, COUNT(*) AS count |
| 5375 | FROM edges e |
| 5376 | JOIN nodes tgt ON tgt.id = e.target |
| 5377 | WHERE tgt.name IN (${placeholders}) |
| 5378 | AND (e.provenance IS NULL OR e.provenance != 'heuristic') |
| 5379 | ${counted} |
| 5380 | GROUP BY tgt.name` |
| 5381 | ) |
| 5382 | .all(...chunk, ...(countedUpToEdgeId === undefined ? [] : [countedUpToEdgeId])) as Array<{ name: string; count: number }>; |
| 5383 | for (const row of counts) { |
| 5384 | if (row.count <= perNameCeiling) keep.push(row.name); |
| 5385 | } |
| 5386 | } |
| 5387 | if (keep.length === 0) return []; |
| 5388 | |
| 5389 | // Pass 2: load the surviving edges with the source file context a |
| 5390 | // resurrection needs. |
| 5391 | const out: Array<Edge & { edgeId: number; sourceFilePath: string; sourceLanguage: Language }> = []; |
| 5392 | for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5393 | const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5394 | const placeholders = chunk.map(() => '?').join(','); |
| 5395 | const rows = this.db |
| 5396 | .prepare( |
| 5397 | `SELECT e.*, src.file_path AS source_file_path, src.language AS source_language |
| 5398 | FROM edges e |
| 5399 | JOIN nodes tgt ON tgt.id = e.target |
| 5400 | JOIN nodes src ON src.id = e.source |
| 5401 | WHERE tgt.name IN (${placeholders}) |
| 5402 | AND (e.provenance IS NULL OR e.provenance != 'heuristic')` |
| 5403 | ) |
| 5404 | .all(...chunk) as Array<EdgeRow & { source_file_path: string; source_language: Language }>; |
| 5405 | for (const row of rows) { |
| 5406 | out.push({ |
| 5407 | ...rowToEdge(row), |
| 5408 | edgeId: row.id, |
| 5409 | sourceFilePath: row.source_file_path, |
| 5410 | sourceLanguage: row.source_language, |
| 5411 | }); |
| 5412 | } |
| 5413 | } |
| 5414 | return out; |
| 5415 | } |
| 5416 |
no test coverage detected