MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / aggregateModuleGraph

Method aggregateModuleGraph

src/db/queries.ts:3412–3504  ·  view source on GitHub ↗

* 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[];
    }
  )

Source from the content-addressed store, hash-verified

3410 * decide the layering puts the storage layer above the CLI.
3411 */
3412 aggregateModuleGraph(
3413 assignments: ReadonlyArray<{ filePath: string; module: string }>,
3414 options: {
3415 kinds: readonly EdgeKind[];
3416 minConfidence: number;
3417 topPairsPerLink: number;
3418 pairKinds: readonly EdgeKind[];
3419 }
3420 ): {
3421 links: Array<{
3422 source: string;
3423 target: string;
3424 kind: EdgeKind;
3425 count: number;
3426 declared: number;
3427 uncertain: number;
3428 }>;
3429 pairs: Array<{
3430 source: string;
3431 target: string;
3432 from: string;
3433 to: string;
3434 count: number;
3435 declared: number;
3436 }>;
3437 } {
3438 if (assignments.length === 0 || options.kinds.length === 0) return { links: [], pairs: [] };
3439
3440 const CONFIDENCE = `COALESCE(json_extract(e.metadata, '$.confidence'), 1)`;
3441 const DECLARED = `(json_extract(e.metadata, '$.resolvedBy') IN ('import', 'qualified-name')
3442 OR e.kind IN ('extends', 'implements')
3443 OR (json_extract(e.metadata, '$.resolvedBy') = 'instance-method'
3444 AND ${CONFIDENCE} >= 0.9))`;
3445
3446 this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map');
3447 this.db.exec('CREATE TEMP TABLE cg_module_map (path TEXT PRIMARY KEY, mod TEXT NOT NULL)');
3448 try {
3449 const insert = this.db.prepare(
3450 'INSERT OR REPLACE INTO cg_module_map (path, mod) VALUES (?, ?)'
3451 );
3452 this.db.exec('BEGIN');
3453 try {
3454 for (const row of assignments) insert.run(row.filePath, row.module);
3455 this.db.exec('COMMIT');
3456 } catch (err) {
3457 this.db.exec('ROLLBACK');
3458 throw err;
3459 }
3460
3461 // ONE pass over the edge table. Grouping by the symbol names as well as
3462 // the modules costs nothing extra in scan time — the join is what is
3463 // expensive — and it buys both results from a single scan. Measured on
3464 // this index inflated to 1.6M edges: 1.66s for this query against 3.0s
3465 // for the module-level and name-level queries run separately, which is
3466 // the difference between meeting and missing the map's cold budget on a
3467 // ten-thousand-file repository.
3468 const rows = this.db
3469 .prepare(

Callers 1

getModuleAggregationMethod · 0.80

Calls 5

foldModuleRowsFunction · 0.85
execMethod · 0.65
prepareMethod · 0.65
runMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected