use VecDeque for todo queues
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
74eb30c106
commit
e21403a4d4
3 changed files with 13 additions and 12 deletions
|
@ -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<HashSet<ShortEventId>> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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::<OwnedEventId>(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");
|
||||
}
|
||||
|
|
|
@ -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<OwnedEventId, _> = HashMap::with_capacity(initial_set.len());
|
||||
let mut eventid_info = HashMap::new();
|
||||
let mut todo_outlier_stack: Vec<OwnedEventId> = initial_set;
|
||||
let mut todo_outlier_stack: VecDeque<OwnedEventId> = 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue