improvement: don't fetch event multiple times

This commit is contained in:
Timo Kösters 2021-12-21 16:02:12 +01:00
parent b1d9ec3efc
commit 54f4d39e3e
No known key found for this signature in database
GPG key ID: 356E705610F626D5
2 changed files with 16 additions and 5 deletions

View file

@ -27,7 +27,9 @@ impl DatabaseEngine for Engine {
db_opts.set_num_levels(8);
db_opts.set_write_buffer_size(2 << 27);
let rocksdb_cache = rocksdb::Cache::new_lru_cache((config.db_cache_capacity_mb * 1024.0 * 1024.0) as usize).unwrap();
let rocksdb_cache =
rocksdb::Cache::new_lru_cache((config.db_cache_capacity_mb * 1024.0 * 1024.0) as usize)
.unwrap();
let mut block_based_options = rocksdb::BlockBasedOptions::default();
block_based_options.set_block_size(2 << 19);

View file

@ -1867,7 +1867,12 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
// handle_outlier_pdu.
let mut todo_auth_events = vec![Arc::clone(id)];
let mut events_in_reverse_order = Vec::new();
let mut events_all = HashSet::new();
while let Some(next_id) = todo_auth_events.pop() {
if events_all.contains(&next_id) {
continue;
}
if let Ok(Some(_)) = db.rooms.get_pdu(&next_id) {
trace!("Found {} in db", id);
continue;
@ -1899,10 +1904,13 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
next_id, calculated_event_id, &res.pdu);
}
if let Some(auth_events) = value.get("auth_events").and_then(|c| c.as_array()) {
if let Some(auth_events) =
value.get("auth_events").and_then(|c| c.as_array())
{
for auth_event in auth_events {
if let Ok(auth_event) = serde_json::from_value(auth_event.clone().into()) {
if let Ok(auth_event) =
serde_json::from_value(auth_event.clone().into())
{
let a: Arc<EventId> = auth_event;
todo_auth_events.push(a);
} else {
@ -1913,7 +1921,8 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
warn!("Auth event list invalid");
}
events_in_reverse_order.push((next_id, value));
events_in_reverse_order.push((next_id.clone(), value));
events_all.insert(next_id);
}
Err(_) => {
warn!("Failed to fetch event: {}", next_id);