deduplicate rooms in hierarchy traversal

This commit is contained in:
reaster authored and Ellis Git committed 2026-07-25 13:55:30 +00:00
1 parent 4727f07e26
commit fb7a378d63
3 files changed
+19 -4

No files matched your search

+10 -1
View File
@@ -210,6 +210,10 @@ impl Service {
let mut summaries = vec![root_summary.summary];
let mut inaccessible_children: HashSet<_> =
root_summary.inaccessible_children.into_iter().collect();
// Rooms already included in the response. The spec requires each room to
// appear at most once, and this also terminates traversal of cyclic space
// graphs (e.g. a space containing itself).
let mut visited: HashSet<OwnedRoomId> = HashSet::from([room_id]);
// TODO refactor this with Vec::peek_mut once it's stabilized
while let Some(layer) = queue.last_mut() {
@@ -224,6 +228,11 @@ impl Service {
continue;
}
// Skip rooms already present in the response
if !visited.insert(room_id.clone()) {
continue;
}
let summary = match self
.get_room_summary_and_children_for_user(
Some(querying_user),
@@ -269,7 +278,7 @@ impl Service {
// suggest you reconsider some of the choices you made which led you to this
// point.
if queue.len() > 50 {
return Err!("Space hierarchy is unreasonably large");
return Err!(Request(TooLarge("Space hierarchy is unreasonably large")));
}
// Add accessible children as a new layer