Take a snapshot of the current graph state. Returns a dict with node and edge counts, qualified names, and community assignments for later diffing.
(store: GraphStore)
| 13 | |
| 14 | |
| 15 | def take_snapshot(store: GraphStore) -> dict[str, Any]: |
| 16 | """Take a snapshot of the current graph state. |
| 17 | |
| 18 | Returns a dict with node and edge counts, qualified names, |
| 19 | and community assignments for later diffing. |
| 20 | """ |
| 21 | stats = store.get_stats() |
| 22 | nodes = store.get_all_nodes(exclude_files=False) |
| 23 | community_map = store.get_all_community_ids() |
| 24 | |
| 25 | return { |
| 26 | "node_count": stats.total_nodes, |
| 27 | "edge_count": stats.total_edges, |
| 28 | "nodes": { |
| 29 | n.qualified_name: { |
| 30 | "kind": n.kind, |
| 31 | "file": n.file_path, |
| 32 | "community_id": community_map.get( |
| 33 | n.qualified_name |
| 34 | ), |
| 35 | } |
| 36 | for n in nodes |
| 37 | }, |
| 38 | "edges": { |
| 39 | f"{e.source_qualified}->" |
| 40 | f"{e.target_qualified}:{e.kind}" |
| 41 | for e in store.get_all_edges() |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | |
| 46 | def save_snapshot(snapshot: dict, path: Path) -> None: |
nothing calls this directly
no test coverage detected