Skip to content
Snippets Groups Projects

refactor fetch_unknown_prev_events

Open Charles Hall requested to merge charles/refactor-fetch-unknown-prev-events into main
1 file
+ 39
40
Compare changes
  • Side-by-side
  • Inline
@@ -1442,7 +1442,7 @@ impl Service {
let mut amount = 0;
while let Some(prev_event_id) = todo_outlier_stack.pop() {
if let Some((pdu, json_opt)) = self
let Some((pdu, json_opt)) = self
.fetch_and_handle_outliers(
origin,
&[prev_event_id.clone()],
@@ -1452,51 +1452,50 @@ impl Service {
)
.await
.pop()
{
Self::check_room_id(room_id, &pdu)?;
else {
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
};
if amount > services().globals.max_fetch_prev_events() {
// Max limit reached
warn!("Max prev event limit reached!");
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
}
Self::check_room_id(room_id, &pdu)?;
if let Some(json) = json_opt.or_else(|| {
services()
.rooms
.outlier
.get_outlier_pdu_json(&prev_event_id)
.ok()
.flatten()
}) {
if pdu.origin_server_ts > first_pdu_in_room.origin_server_ts
{
amount += 1;
for prev_prev in &pdu.prev_events {
if !graph.contains_key(prev_prev) {
todo_outlier_stack.push(prev_prev.clone());
}
}
if amount > services().globals.max_fetch_prev_events() {
warn!("Max prev event limit reached");
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
}
graph.insert(
prev_event_id.clone(),
pdu.prev_events.iter().cloned().collect(),
);
} else {
// Time based check failed
graph.insert(prev_event_id.clone(), HashSet::new());
}
let Some(json) = json_opt.or_else(|| {
services()
.rooms
.outlier
.get_outlier_pdu_json(&prev_event_id)
.ok()
.flatten()
}) else {
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
};
eventid_info.insert(prev_event_id.clone(), (pdu, json));
} else {
// Get json failed, so this was not fetched over federation
graph.insert(prev_event_id.clone(), HashSet::new());
}
} else {
// Fetch and handle failed
if pdu.origin_server_ts <= first_pdu_in_room.origin_server_ts {
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
}
amount += 1;
for prev_prev in &pdu.prev_events {
if !graph.contains_key(prev_prev) {
todo_outlier_stack.push(prev_prev.clone());
}
}
graph.insert(
prev_event_id.clone(),
pdu.prev_events.iter().cloned().collect(),
);
eventid_info.insert(prev_event_id.clone(), (pdu, json));
}
let sorted =
Loading