diff --git a/src/service/rooms/auth_chain/mod.rs b/src/service/rooms/auth_chain/mod.rs index 796eb5d2..67883d01 100644 --- a/src/service/rooms/auth_chain/mod.rs +++ b/src/service/rooms/auth_chain/mod.rs @@ -1,7 +1,7 @@ mod data; use std::{ - collections::{BTreeSet, HashSet}, + collections::{BTreeSet, HashSet, VecDeque}, fmt::Debug, sync::Arc, }; @@ -185,10 +185,10 @@ impl Service { room_id: &RoomId, event_id: &EventId, ) -> Result> { - let mut todo = vec![event_id.to_owned()]; + let mut todo: VecDeque<_> = [event_id.to_owned()].into(); let mut found = HashSet::new(); - while let Some(event_id) = todo.pop() { + while let Some(event_id) = todo.pop_front() { trace!(?event_id, "processing auth event"); match self.services.timeline.get_pdu(&event_id).await { @@ -218,7 +218,8 @@ impl Service { ?auth_event, "adding auth event to processing queue" ); - todo.push(auth_event.clone()); + + todo.push_back(auth_event.clone()); } } }, diff --git a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs index f980ca24..1bad4659 100644 --- a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs +++ b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map, BTreeMap, HashSet}, + collections::{hash_map, BTreeMap, HashSet, VecDeque}, sync::Arc, time::Instant, }; @@ -62,10 +62,10 @@ pub(super) async fn fetch_and_handle_outliers<'a>( // c. Ask origin server over federation // We also handle its auth chain here so we don't get a stack overflow in // handle_outlier_pdu. - let mut todo_auth_events = vec![id.clone()]; + let mut todo_auth_events: VecDeque<_> = [id.clone()].into(); let mut events_in_reverse_order = Vec::with_capacity(todo_auth_events.len()); let mut events_all = HashSet::with_capacity(todo_auth_events.len()); - while let Some(next_id) = todo_auth_events.pop() { + while let Some(next_id) = todo_auth_events.pop_front() { if let Some((time, tries)) = self .services .globals @@ -132,7 +132,7 @@ pub(super) async fn fetch_and_handle_outliers<'a>( if let Ok(auth_event) = serde_json::from_value::(auth_event.clone().into()) { - todo_auth_events.push(auth_event); + todo_auth_events.push_back(auth_event); } else { warn!("Auth event id is not valid"); } diff --git a/src/service/rooms/event_handler/fetch_prev.rs b/src/service/rooms/event_handler/fetch_prev.rs index ca93e11d..3f121f69 100644 --- a/src/service/rooms/event_handler/fetch_prev.rs +++ b/src/service/rooms/event_handler/fetch_prev.rs @@ -1,5 +1,5 @@ use std::{ - collections::{BTreeMap, HashMap, HashSet}, + collections::{BTreeMap, HashMap, HashSet, VecDeque}, sync::Arc, }; @@ -30,13 +30,13 @@ pub(super) async fn fetch_prev( )> { let mut graph: HashMap = HashMap::with_capacity(initial_set.len()); let mut eventid_info = HashMap::new(); - let mut todo_outlier_stack: Vec = initial_set; + let mut todo_outlier_stack: VecDeque = initial_set.into(); let first_pdu_in_room = self.services.timeline.first_pdu_in_room(room_id).await?; let mut amount = 0; - while let Some(prev_event_id) = todo_outlier_stack.pop() { + while let Some(prev_event_id) = todo_outlier_stack.pop_front() { self.services.server.check_running()?; if let Some((pdu, mut json_opt)) = self @@ -74,7 +74,7 @@ pub(super) async fn fetch_prev( amount = amount.saturating_add(1); for prev_prev in &pdu.prev_events { if !graph.contains_key(prev_prev) { - todo_outlier_stack.push(prev_prev.clone()); + todo_outlier_stack.push_back(prev_prev.clone()); } }