Hoist room_version query to callers of get_auth_chain.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-01-21 16:53:56 +00:00
parent afcb2315ee
commit 48aa6035f6
8 changed files with 49 additions and 59 deletions

View File

@@ -11,10 +11,10 @@ use futures::{
FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, pin_mut,
stream::{FuturesUnordered, unfold},
};
use ruma::{EventId, OwnedEventId, RoomId, room_version_rules::RoomVersionRules};
use ruma::{EventId, OwnedEventId, RoomId, RoomVersionId, room_version_rules::RoomVersionRules};
use tuwunel_core::{
Err, Result, at, debug, debug_error, err, implement,
matrix::{Event, PduEvent},
matrix::{Event, PduEvent, room_version},
pdu::AuthEvents,
trace, utils,
utils::{
@@ -60,12 +60,13 @@ impl crate::Service for Service {
pub fn event_ids_iter<'a, I>(
&'a self,
room_id: &'a RoomId,
room_version: &'a RoomVersionId,
starting_events: I,
) -> impl Stream<Item = Result<OwnedEventId>> + Send + 'a
where
I: Iterator<Item = &'a EventId> + Clone + Debug + ExactSizeIterator + Send + 'a,
{
self.get_auth_chain(room_id, starting_events)
self.get_auth_chain(room_id, room_version, starting_events)
.map_ok(|chain| {
self.services
.short
@@ -85,6 +86,7 @@ where
pub async fn get_auth_chain<'a, I>(
&'a self,
room_id: &RoomId,
room_version: &RoomVersionId,
starting_events: I,
) -> Result<Vec<ShortEventId>>
where
@@ -94,12 +96,7 @@ where
const BUCKET: Bucket<'_> = BTreeSet::new();
let started = Instant::now();
let room_rules = self
.services
.state
.get_room_version_rules(room_id)
.await?;
let room_rules = room_version::rules(room_version)?;
let starting_ids = self
.services
.short

View File

@@ -17,7 +17,7 @@ use crate::rooms::state_compressor::CompressedState;
pub async fn resolve_state(
&self,
room_id: &RoomId,
room_version_id: &RoomVersionId,
room_version: &RoomVersionId,
incoming_state: HashMap<u64, OwnedEventId>,
) -> Result<Arc<CompressedState>> {
trace!("Loading current room state ids");
@@ -43,7 +43,7 @@ pub async fn resolve_state(
.wide_and_then(|state| {
self.services
.auth_chain
.event_ids_iter(room_id, state.values().map(Borrow::borrow))
.event_ids_iter(room_id, room_version, state.values().map(Borrow::borrow))
.try_collect::<AuthSet<OwnedEventId>>()
})
.ready_filter_map(Result::ok);
@@ -64,7 +64,7 @@ pub async fn resolve_state(
trace!("Resolving state");
let state = self
.state_resolution(room_version_id, fork_states, auth_chain_sets)
.state_resolution(room_version, fork_states, auth_chain_sets)
.await?;
trace!("State resolution done.");

View File

@@ -104,7 +104,7 @@ pub(super) async fn state_at_incoming_resolved<Pdu>(
&self,
incoming_pdu: &Pdu,
room_id: &RoomId,
room_version_id: &RoomVersionId,
room_version: &RoomVersionId,
) -> Result<Option<HashMap<u64, OwnedEventId>>>
where
Pdu: Event,
@@ -141,7 +141,7 @@ where
.into_iter()
.try_stream()
.wide_and_then(|(sstatehash, prev_event)| {
self.state_at_incoming_fork(room_id, sstatehash, prev_event)
self.state_at_incoming_fork(room_id, room_version, sstatehash, prev_event)
})
.try_collect()
.map_ok(Vec::into_iter)
@@ -152,7 +152,7 @@ where
trace!("Resolving state");
let Ok(new_state) = self
.state_resolution(room_version_id, fork_states, auth_chain_sets)
.state_resolution(room_version, fork_states, auth_chain_sets)
.inspect_ok(|_| trace!("State resolution done."))
.await
else {
@@ -189,6 +189,7 @@ where
async fn state_at_incoming_fork<Pdu>(
&self,
room_id: &RoomId,
room_version: &RoomVersionId,
sstatehash: ShortStateHash,
prev_event: Pdu,
) -> Result<(StateMap<OwnedEventId>, AuthSet<OwnedEventId>)>
@@ -228,7 +229,7 @@ where
let auth_chain = self
.services
.auth_chain
.event_ids_iter(room_id, starting_events)
.event_ids_iter(room_id, room_version, starting_events)
.try_collect();
let fork_state = leaf_state_after_event