mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 04:37:00 +00:00
deduplicate rooms in hierarchy traversal
This commit is contained in:
1 parent
4727f07e26
commit
fb7a378d63
3 files changed
+19
-4
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user