From 95bb153269075015e5c36784aa0f1e40d8a215a9 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 29 Aug 2025 13:57:14 +0300 Subject: [PATCH] chore(spaces): improve how space graph edge additions work --- crates/matrix-sdk-ui/src/spaces/graph.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/matrix-sdk-ui/src/spaces/graph.rs b/crates/matrix-sdk-ui/src/spaces/graph.rs index b8c0a1b22..1b788dd8b 100644 --- a/crates/matrix-sdk-ui/src/spaces/graph.rs +++ b/crates/matrix-sdk-ui/src/spaces/graph.rs @@ -69,12 +69,13 @@ impl SpaceGraph { /// Adds a directed edge from `parent_id` to `child_id`, creating nodes if /// they do not already exist in the graph. pub(super) fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) { - self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone())); + let parent_entry = + self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone())); + parent_entry.children.insert(child_id.clone()); - self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id.clone())); - - self.nodes.get_mut(&parent_id).unwrap().children.insert(child_id.clone()); - self.nodes.get_mut(&child_id).unwrap().parents.insert(parent_id); + let child_entry = + self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id)); + child_entry.parents.insert(parent_id); } /// Removes cycles in the graph by performing a depth-first search (DFS) and