state-res: Allocate less when computing all_conflicted

This commit is contained in:
Jonas Platte 2021-09-07 13:30:46 +02:00
parent 6559681095
commit b31065827b
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -78,21 +78,14 @@ where
info!("conflicting events: {}", conflicting.len()); info!("conflicting events: {}", conflicting.len());
debug!("{:?}", conflicting); debug!("{:?}", conflicting);
// The set of auth events that are not common across server forks
let mut auth_diff: HashSet<_> = get_auth_chain_diff(auth_chain_sets).collect();
// Add the auth_diff to conflicting now we have a full set of conflicting events
auth_diff.extend(conflicting.values().cloned().flatten().flatten());
debug!("auth diff: {}", auth_diff.len());
trace!("{:?}", auth_diff);
// `all_conflicted` contains unique items // `all_conflicted` contains unique items
// synapse says `full_set = {eid for eid in full_conflicted_set if eid in event_map}` // synapse says `full_set = {eid for eid in full_conflicted_set if eid in event_map}`
// let all_conflicted: HashSet<_> = get_auth_chain_diff(auth_chain_sets)
// FIXME: Use into_values() once MSRV >= 1.54
.chain(conflicting.into_iter().flat_map(|(_k, v)| v).flatten())
// Don't honor events we cannot "verify" // Don't honor events we cannot "verify"
auth_diff.retain(|id| fetch_event(id).is_some()); .filter(|id| fetch_event(id).is_some())
let all_conflicted = auth_diff; .collect();
info!("full conflicted set: {}", all_conflicted.len()); info!("full conflicted set: {}", all_conflicted.len());
debug!("{:?}", all_conflicted); debug!("{:?}", all_conflicted);