* 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
)
| 5246 | * that stays below it. |
| 5247 | */ |
| 5248 | getResolutionEdgesByTargetName( |
| 5249 | names: string[], |
| 5250 | perNameCeiling: number = 500, |
| 5251 | countedUpToEdgeId?: number |
| 5252 | ): Array<Edge & { edgeId: number; sourceFilePath: string; sourceLanguage: Language }> { |
| 5253 | if (names.length === 0) return []; |
| 5254 | |
| 5255 | // Pass 1: per-name edge counts, chunked under the SQLite parameter limit. |
| 5256 | const keep: string[] = []; |
| 5257 | const counted = countedUpToEdgeId === undefined ? '' : 'AND e.id <= ?'; |
| 5258 | for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5259 | const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5260 | const placeholders = chunk.map(() => '?').join(','); |
| 5261 | const counts = this.db |
| 5262 | .prepare( |
| 5263 | `SELECT tgt.name AS name, COUNT(*) AS count |
| 5264 | FROM edges e |
| 5265 | JOIN nodes tgt ON tgt.id = e.target |
| 5266 | WHERE tgt.name IN (${placeholders}) |
| 5267 | AND (e.provenance IS NULL OR e.provenance != 'heuristic') |
| 5268 | ${counted} |
| 5269 | GROUP BY tgt.name` |
| 5270 | ) |
| 5271 | .all(...chunk, ...(countedUpToEdgeId === undefined ? [] : [countedUpToEdgeId])) as Array<{ name: string; count: number }>; |
| 5272 | for (const row of counts) { |
| 5273 | if (row.count <= perNameCeiling) keep.push(row.name); |
| 5274 | } |
| 5275 | } |
| 5276 | if (keep.length === 0) return []; |
| 5277 | |
| 5278 | // Pass 2: load the surviving edges with the source file context a |
| 5279 | // resurrection needs. |
| 5280 | const out: Array<Edge & { edgeId: number; sourceFilePath: string; sourceLanguage: Language }> = []; |
| 5281 | for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) { |
| 5282 | const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE); |
| 5283 | const placeholders = chunk.map(() => '?').join(','); |
| 5284 | const rows = this.db |
| 5285 | .prepare( |
| 5286 | `SELECT e.*, src.file_path AS source_file_path, src.language AS source_language |
| 5287 | FROM edges e |
| 5288 | JOIN nodes tgt ON tgt.id = e.target |
| 5289 | JOIN nodes src ON src.id = e.source |
| 5290 | WHERE tgt.name IN (${placeholders}) |
| 5291 | AND (e.provenance IS NULL OR e.provenance != 'heuristic')` |
| 5292 | ) |
| 5293 | .all(...chunk) as Array<EdgeRow & { source_file_path: string; source_language: Language }>; |
| 5294 | for (const row of rows) { |
| 5295 | out.push({ |
| 5296 | ...rowToEdge(row), |
| 5297 | edgeId: row.id, |
| 5298 | sourceFilePath: row.source_file_path, |
| 5299 | sourceLanguage: row.source_language, |
| 5300 | }); |
| 5301 | } |
| 5302 | } |
| 5303 | return out; |
| 5304 | } |
| 5305 |
no test coverage detected