Skip to main content

build_import_graph

Function build_import_graph 

pub fn build_import_graph(db: &FactsDb) -> Result<Rc<ImportGraph>>
Expand description

Build the directed import graph over every live Tier-1 source file. Nodes are seeded from complexity_metrics (one row per parsed source file, isolated files included) and edges from the resolved rows in the imports table (target_path IS NOT NULL). Seeding from all source files — not just resolved endpoints — keeps a file that neither imports nor is imported in n, so propagation_cost and cycle share are computed over the full component set (per MacCormack/Lakos). Parallel edges are deduped and self-loops dropped — neither affects reachability or SCC membership, and removing them keeps the adjacency tight.

Memoised per FactsDb: the graph is a pure function of the immutable complexity_metrics (node set) + imports (edges) tables, so the several architecture analyses that each call this in one process (SPA dashboard, codelore check arch-suite) share a single build through the returned Rc handle.

§Errors

Returns crate::CodeLoreError::Analysis on DuckDB query errors.