mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-17 23:52:36 +00:00
PR #980 in-line review flagged that `removeNode` iterated the full relationshipMap to find edges touching a node (O(E)), and `removeNodesByFile` called removeNode for every matching node after a full nodeMap scan (O(N × E)). Pre-existing, but worth fixing properly since the writeRel/deleteRel helpers we just added make the index-maintenance story coherent. Two new indexes maintained on every mutation path: - `edgeIdsByNode: Map<nodeId, Set<relId>>` — reverse adjacency. Every edge records both endpoints, so removeNode iterates edgeIdsByNode.get(id) instead of every relationship. Self-edges skip the duplicate-endpoint write to keep the Set dedup explicit. - `nodeIdsByFile: Map<filePath, Set<nodeId>>` — file index. removeNodesByFile reaches its file's nodes directly. Complexity: - removeNode: O(edges-touching-node), was O(total-edges). - removeNodesByFile: O(file-nodes × avg-edges-per-node + scan of the file bucket), was O(total-nodes + file-nodes × total-edges). Index maintenance is centralized in writeRel/deleteRel + new addToBucket/removeFromBucket helpers. Empty buckets are pruned to keep the indexes compact. Existing dual-invariant (relationshipMap ↔ relationshipsByType) preserved. Nodes without a `filePath` property (e.g. Community/Cluster nodes) are intentionally NOT indexed in nodeIdsByFile — they can't belong to any file, so removeNodesByFile correctly leaves them alone. Coverage: 7 new unit tests (33/33 total, was 26). Added cases: - removes only edges touching the removed node - handles self-edges - removes orphan node with no edges - removeNodesByFile removes only matching nodes - returns 0 when no match - also removes edges whose endpoints lived on the removed file - does not index nodes without a filePath property Verification: 204/204 test/integration/resolvers/python.test.ts both REGISTRY_PRIMARY_PYTHON=0 and =1. 4235/4235 unit tests. tsc clean. |
||
|---|---|---|
| .. | ||
| fixtures | ||
| helpers | ||
| integration | ||
| unit | ||
| utils | ||
| global-setup.ts | ||
| vitest.d.ts | ||