1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-11-04 17:18:51 +01:00

improvement: better auth chain calculation

This commit is contained in:
Timo Kösters 2021-08-03 19:18:41 +02:00
parent 41ec7cf5d0
commit fce22362d4
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4

View file

@ -1732,7 +1732,7 @@ fn get_auth_chain(starting_events: Vec<EventId>, db: &Database) -> Result<HashSe
cached.clone()
} else {
drop(cache);
let auth_chain = get_auth_chain_recursive(&event_id, db)?;
let auth_chain = get_auth_chain_recursive(&event_id, HashSet::new(), db)?;
cache = db.rooms.auth_chain_cache();
@ -1747,19 +1747,19 @@ fn get_auth_chain(starting_events: Vec<EventId>, db: &Database) -> Result<HashSe
Ok(full_auth_chain)
}
fn get_auth_chain_recursive(event_id: &EventId, db: &Database) -> Result<HashSet<EventId>> {
let mut auth_chain = HashSet::new();
fn get_auth_chain_recursive(event_id: &EventId, mut found: HashSet<EventId>, db: &Database) -> Result<HashSet<EventId>> {
if let Some(pdu) = db.rooms.get_pdu(&event_id)? {
auth_chain.extend(pdu.auth_events.iter().cloned());
for auth_event in &pdu.auth_events {
auth_chain.extend(get_auth_chain_recursive(&auth_event, db)?);
if !found.contains(auth_event) {
found.insert(auth_event.clone());
found = get_auth_chain_recursive(&auth_event, found, db)?;
}
}
} else {
warn!("Could not find pdu mentioned in auth events.");
}
Ok(auth_chain)
Ok(found)
}
#[cfg_attr(