pass stream width to ruma state res

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-24 14:43:28 +00:00 committed by strawberry
parent 3b95af9a18
commit 5a335933b8
4 changed files with 48 additions and 53 deletions

View file

@ -6,7 +6,7 @@ use std::{
use conduwuit::{
debug, err, implement,
utils::stream::{IterStream, WidebandExt},
utils::stream::{automatic_width, IterStream, WidebandExt},
Result,
};
use futures::{FutureExt, StreamExt, TryFutureExt};
@ -75,22 +75,10 @@ pub async fn resolve_state(
.await;
debug!("Resolving state");
let lock = self.services.globals.stateres_mutex.lock();
let event_fetch = |event_id| self.event_fetch(event_id);
let event_exists = |event_id| self.event_exists(event_id);
let state = state_res::resolve(
room_version_id,
&fork_states,
&auth_chain_sets,
&event_fetch,
&event_exists,
)
.boxed()
.await
.map_err(|e| err!(Database(error!("State resolution failed: {e:?}"))))?;
drop(lock);
let state = self
.state_resolution(room_version_id, &fork_states, &auth_chain_sets)
.boxed()
.await?;
debug!("State resolution done.");
let state_events: Vec<_> = state
@ -119,3 +107,26 @@ pub async fn resolve_state(
Ok(Arc::new(new_room_state))
}
#[implement(super::Service)]
#[tracing::instrument(name = "ruma", level = "debug", skip_all)]
pub async fn state_resolution(
&self,
room_version: &RoomVersionId,
state_sets: &[StateMap<Arc<EventId>>],
auth_chain_sets: &Vec<HashSet<Arc<EventId>>>,
) -> Result<StateMap<Arc<EventId>>> {
//TODO: ???
let _lock = self.services.globals.stateres_mutex.lock();
state_res::resolve(
room_version,
state_sets.iter(),
auth_chain_sets,
&|event_id| self.event_fetch(event_id),
&|event_id| self.event_exists(event_id),
automatic_width(),
)
.await
.map_err(|e| err!(error!("State resolution failed: {e:?}")))
}

View file

@ -11,10 +11,7 @@ use conduwuit::{
PduEvent, Result,
};
use futures::{FutureExt, StreamExt};
use ruma::{
state_res::{self, StateMap},
EventId, RoomId, RoomVersionId,
};
use ruma::{state_res::StateMap, EventId, RoomId, RoomVersionId};
// TODO: if we know the prev_events of the incoming event we can avoid the
#[implement(super::Service)]
@ -157,24 +154,11 @@ pub(super) async fn state_at_incoming_resolved(
fork_states.push(state);
}
let lock = self.services.globals.stateres_mutex.lock();
let event_fetch = |event_id| self.event_fetch(event_id);
let event_exists = |event_id| self.event_exists(event_id);
let result = state_res::resolve(
room_version_id,
&fork_states,
&auth_chain_sets,
&event_fetch,
&event_exists,
)
.boxed()
.await
.map_err(|e| err!(Database(warn!(?e, "State resolution on prev events failed."))));
drop(lock);
let Ok(new_state) = result else {
let Ok(new_state) = self
.state_resolution(room_version_id, &fork_states, &auth_chain_sets)
.boxed()
.await
else {
return Ok(None);
};