Skip to content

Commit aa27a64

Browse files
committed
chore(spaces): improve how space graph edge additions work
1 parent af195ea commit aa27a64

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

crates/matrix-sdk-ui/src/spaces/graph.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ impl SpaceGraph {
6969
/// Adds a directed edge from `parent_id` to `child_id`, creating nodes if
7070
/// they do not already exist in the graph.
7171
pub(super) fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) {
72-
self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone()));
72+
let parent_entry =
73+
self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone()));
74+
parent_entry.children.insert(child_id.clone());
7375

74-
self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id.clone()));
75-
76-
self.nodes.get_mut(&parent_id).unwrap().children.insert(child_id.clone());
77-
self.nodes.get_mut(&child_id).unwrap().parents.insert(parent_id);
76+
let child_entry =
77+
self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id));
78+
child_entry.parents.insert(parent_id);
7879
}
7980

8081
/// Removes cycles in the graph by performing a depth-first search (DFS) and

0 commit comments

Comments
 (0)