Remove so many allocations for auth chain, address review
This commit is contained in:
parent
41b8c14d6e
commit
509283d947
10
src/lib.rs
10
src/lib.rs
@ -226,6 +226,8 @@ impl StateResolution {
|
||||
_room_id: &RoomId,
|
||||
auth_event_ids: &[Vec<EventId>],
|
||||
) -> Result<Vec<EventId>> {
|
||||
use itertools::Itertools;
|
||||
|
||||
let mut chains = vec![];
|
||||
|
||||
for ids in auth_event_ids {
|
||||
@ -235,17 +237,15 @@ impl StateResolution {
|
||||
chains.push(chain);
|
||||
}
|
||||
|
||||
if let Some(chain) = chains.first() {
|
||||
if let Some(chain) = chains.first().cloned() {
|
||||
let rest = chains.iter().skip(1).flatten().cloned().collect();
|
||||
let common = chain.intersection(&rest).collect::<Vec<_>>();
|
||||
|
||||
Ok(chains
|
||||
.iter()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|id| !common.contains(&id))
|
||||
.cloned()
|
||||
.collect::<BTreeSet<_>>()
|
||||
.into_iter()
|
||||
.dedup()
|
||||
.collect())
|
||||
} else {
|
||||
Ok(vec![])
|
||||
|
@ -38,18 +38,19 @@ pub struct RoomVersion {
|
||||
/// not sure
|
||||
pub enforce_key_validity: bool,
|
||||
|
||||
// bool: before MSC2261/MSC2432,
|
||||
/// `m.room.aliases` had special auth rules and redaction rules
|
||||
/// before room version 6.
|
||||
///
|
||||
/// before MSC2261/MSC2432,
|
||||
pub special_case_aliases_auth: bool,
|
||||
/// Strictly enforce canonicaljson, do not allow:
|
||||
/// * Integers outside the range of [-2 ^ 53 + 1, 2 ^ 53 - 1]
|
||||
/// * Floats
|
||||
/// * NaN, Infinity, -Infinity
|
||||
pub strict_canonicaljson: bool,
|
||||
// bool: MSC2209: Check 'notifications' key while verifying
|
||||
// m.room.power_levels auth rules.
|
||||
/// Verify notifications key while checking m.room.power_levels.
|
||||
///
|
||||
/// bool: MSC2209: Check 'notifications'
|
||||
pub limit_notifications_power_levels: bool,
|
||||
/// Extra rules when verifying redaction events.
|
||||
pub extra_redaction_checks: bool,
|
||||
@ -73,7 +74,7 @@ impl RoomVersion {
|
||||
})
|
||||
}
|
||||
|
||||
fn version_1() -> Self {
|
||||
pub fn version_1() -> Self {
|
||||
Self {
|
||||
version: RoomVersionId::Version1,
|
||||
disposition: RoomDisposition::Stable,
|
||||
@ -87,7 +88,7 @@ impl RoomVersion {
|
||||
}
|
||||
}
|
||||
|
||||
fn version_2() -> Self {
|
||||
pub fn version_2() -> Self {
|
||||
Self {
|
||||
version: RoomVersionId::Version2,
|
||||
disposition: RoomDisposition::Stable,
|
||||
@ -101,7 +102,7 @@ impl RoomVersion {
|
||||
}
|
||||
}
|
||||
|
||||
fn version_3() -> Self {
|
||||
pub fn version_3() -> Self {
|
||||
Self {
|
||||
version: RoomVersionId::Version3,
|
||||
disposition: RoomDisposition::Stable,
|
||||
@ -115,7 +116,7 @@ impl RoomVersion {
|
||||
}
|
||||
}
|
||||
|
||||
fn version_4() -> Self {
|
||||
pub fn version_4() -> Self {
|
||||
Self {
|
||||
version: RoomVersionId::Version4,
|
||||
disposition: RoomDisposition::Stable,
|
||||
@ -129,7 +130,7 @@ impl RoomVersion {
|
||||
}
|
||||
}
|
||||
|
||||
fn version_5() -> Self {
|
||||
pub fn version_5() -> Self {
|
||||
Self {
|
||||
version: RoomVersionId::Version5,
|
||||
disposition: RoomDisposition::Stable,
|
||||
@ -143,7 +144,7 @@ impl RoomVersion {
|
||||
}
|
||||
}
|
||||
|
||||
fn version_6() -> Self {
|
||||
pub fn version_6() -> Self {
|
||||
Self {
|
||||
version: RoomVersionId::Version6,
|
||||
disposition: RoomDisposition::Stable,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{events::EventType, EventId, RoomVersionId};
|
||||
use ruma::{events::EventType, EventId};
|
||||
use state_res::{is_power_event, room_version::RoomVersion, StateMap};
|
||||
|
||||
mod utils;
|
||||
@ -46,7 +46,7 @@ fn test_event_sort() {
|
||||
// TODO we may be able to skip this since they are resolved according to spec
|
||||
let resolved_power = state_res::StateResolution::iterative_auth_check(
|
||||
&room_id(),
|
||||
&RoomVersion::new(&RoomVersionId::Version6).unwrap(),
|
||||
&RoomVersion::version_6(),
|
||||
&sorted_power_events,
|
||||
&BTreeMap::new(), // unconflicted events
|
||||
&mut events,
|
||||
|
@ -260,6 +260,7 @@ impl<E: Event> TestStore<E> {
|
||||
room_id: &RoomId,
|
||||
event_ids: Vec<Vec<EventId>>,
|
||||
) -> Result<Vec<EventId>> {
|
||||
use itertools::Itertools;
|
||||
let mut chains = vec![];
|
||||
for ids in event_ids {
|
||||
// TODO state store `auth_event_ids` returns self in the event ids list
|
||||
@ -271,17 +272,15 @@ impl<E: Event> TestStore<E> {
|
||||
chains.push(chain);
|
||||
}
|
||||
|
||||
if let Some(chain) = chains.first() {
|
||||
if let Some(chain) = chains.first().cloned() {
|
||||
let rest = chains.iter().skip(1).flatten().cloned().collect();
|
||||
let common = chain.intersection(&rest).collect::<Vec<_>>();
|
||||
|
||||
Ok(chains
|
||||
.iter()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|id| !common.contains(&id))
|
||||
.cloned()
|
||||
.collect::<BTreeSet<_>>()
|
||||
.into_iter()
|
||||
.dedup()
|
||||
.collect())
|
||||
} else {
|
||||
Ok(vec![])
|
||||
|
Loading…
x
Reference in New Issue
Block a user