minor auth_chain optimizations/cleanup

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-25 03:52:28 +00:00 committed by strawberry
parent 4776fe66c4
commit 3f7ec4221d
8 changed files with 125 additions and 118 deletions

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::borrow::Borrow;
use axum::extract::State;
use conduit::{Error, Result};
@ -57,7 +57,7 @@ pub(crate) async fn get_event_authorization_route(
let auth_chain = services
.rooms
.auth_chain
.event_ids_iter(room_id, vec![Arc::from(&*body.event_id)])
.event_ids_iter(room_id, &[body.event_id.borrow()])
.await?
.filter_map(|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() })
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))

View file

@ -1,6 +1,6 @@
#![allow(deprecated)]
use std::collections::BTreeMap;
use std::{borrow::Borrow, collections::BTreeMap};
use axum::extract::State;
use conduit::{err, pdu::gen_event_id_canonical_json, utils::IterStream, warn, Error, Result};
@ -11,7 +11,7 @@ use ruma::{
room::member::{MembershipState, RoomMemberEventContent},
StateEventType,
},
CanonicalJsonValue, OwnedServerName, OwnedUserId, RoomId, ServerName,
CanonicalJsonValue, EventId, OwnedServerName, OwnedUserId, RoomId, ServerName,
};
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use service::Services;
@ -196,10 +196,11 @@ async fn create_join_event(
.try_collect()
.await?;
let starting_events: Vec<&EventId> = state_ids.values().map(Borrow::borrow).collect();
let auth_chain = services
.rooms
.auth_chain
.event_ids_iter(room_id, state_ids.values().cloned().collect())
.event_ids_iter(room_id, &starting_events)
.await?
.map(Ok)
.and_then(|event_id| async move { services.rooms.timeline.get_pdu_json(&event_id).await })

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::borrow::Borrow;
use axum::extract::State;
use conduit::{err, result::LogErr, utils::IterStream, Err, Result};
@ -63,7 +63,7 @@ pub(crate) async fn get_room_state_route(
let auth_chain = services
.rooms
.auth_chain
.event_ids_iter(&body.room_id, vec![Arc::from(&*body.event_id)])
.event_ids_iter(&body.room_id, &[body.event_id.borrow()])
.await?
.map(Ok)
.and_then(|id| async move { services.rooms.timeline.get_pdu_json(&id).await })

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::borrow::Borrow;
use axum::extract::State;
use conduit::{err, Err};
@ -55,7 +55,7 @@ pub(crate) async fn get_room_state_ids_route(
let auth_chain_ids = services
.rooms
.auth_chain
.event_ids_iter(&body.room_id, vec![Arc::from(&*body.event_id)])
.event_ids_iter(&body.room_id, &[body.event_id.borrow()])
.await?
.map(|id| (*id).to_owned())
.collect()