* Roll the whole edge table up to module granularity in one pass. * * The caller decides what a module IS — it hands in a file → module * assignment and gets back the cross-module traffic. That split is * deliberate: naming modules is a *policy* (top-level directories, a façade * file
(
assignments: ReadonlyArray<{ filePath: string; module: string }>,
options: {
kinds: readonly EdgeKind[];
minConfidence: number;
topPairsPerLink: number;
pairKinds: readonly EdgeKind[];
}
)
| 3376 | * decide the layering puts the storage layer above the CLI. |
| 3377 | */ |
| 3378 | aggregateModuleGraph( |
| 3379 | assignments: ReadonlyArray<{ filePath: string; module: string }>, |
| 3380 | options: { |
| 3381 | kinds: readonly EdgeKind[]; |
| 3382 | minConfidence: number; |
| 3383 | topPairsPerLink: number; |
| 3384 | pairKinds: readonly EdgeKind[]; |
| 3385 | } |
| 3386 | ): { |
| 3387 | links: Array<{ |
| 3388 | source: string; |
| 3389 | target: string; |
| 3390 | kind: EdgeKind; |
| 3391 | count: number; |
| 3392 | declared: number; |
| 3393 | uncertain: number; |
| 3394 | }>; |
| 3395 | pairs: Array<{ |
| 3396 | source: string; |
| 3397 | target: string; |
| 3398 | from: string; |
| 3399 | to: string; |
| 3400 | count: number; |
| 3401 | declared: number; |
| 3402 | }>; |
| 3403 | } { |
| 3404 | if (assignments.length === 0 || options.kinds.length === 0) return { links: [], pairs: [] }; |
| 3405 | |
| 3406 | const CONFIDENCE = `COALESCE(json_extract(e.metadata, '$.confidence'), 1)`; |
| 3407 | const DECLARED = `(json_extract(e.metadata, '$.resolvedBy') IN ('import', 'qualified-name') |
| 3408 | OR e.kind IN ('extends', 'implements') |
| 3409 | OR (json_extract(e.metadata, '$.resolvedBy') = 'instance-method' |
| 3410 | AND ${CONFIDENCE} >= 0.9))`; |
| 3411 | |
| 3412 | this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map'); |
| 3413 | this.db.exec('CREATE TEMP TABLE cg_module_map (path TEXT PRIMARY KEY, mod TEXT NOT NULL)'); |
| 3414 | try { |
| 3415 | const insert = this.db.prepare( |
| 3416 | 'INSERT OR REPLACE INTO cg_module_map (path, mod) VALUES (?, ?)' |
| 3417 | ); |
| 3418 | this.db.exec('BEGIN'); |
| 3419 | try { |
| 3420 | for (const row of assignments) insert.run(row.filePath, row.module); |
| 3421 | this.db.exec('COMMIT'); |
| 3422 | } catch (err) { |
| 3423 | this.db.exec('ROLLBACK'); |
| 3424 | throw err; |
| 3425 | } |
| 3426 | |
| 3427 | // ONE pass over the edge table. Grouping by the symbol names as well as |
| 3428 | // the modules costs nothing extra in scan time — the join is what is |
| 3429 | // expensive — and it buys both results from a single scan. Measured on |
| 3430 | // this index inflated to 1.6M edges: 1.66s for this query against 3.0s |
| 3431 | // for the module-level and name-level queries run separately, which is |
| 3432 | // the difference between meeting and missing the map's cold budget on a |
| 3433 | // ten-thousand-file repository. |
| 3434 | const rows = this.db |
| 3435 | .prepare( |
no test coverage detected