optimize further into state-res with SmallString

triage and de-lints for state-res.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-02-08 01:58:13 +00:00 committed by strawberry
parent 0a9a9b3c92
commit f2ca670c3b
15 changed files with 192 additions and 145 deletions

View file

@ -133,7 +133,7 @@ pub(super) async fn handle_outlier_pdu<'a>(
));
}
let state_fetch = |ty: &'static StateEventType, sk: &str| {
let state_fetch = |ty: &StateEventType, sk: &str| {
let key = (ty.to_owned(), sk.into());
ready(auth_events.get(&key))
};

View file

@ -63,7 +63,6 @@ pub async fn resolve_state(
.multi_get_statekey_from_short(shortstatekeys)
.zip(event_ids)
.ready_filter_map(|(ty_sk, id)| Some((ty_sk.ok()?, id)))
.map(|((ty, sk), id)| ((ty, sk.as_str().to_owned()), id))
.collect()
})
.map(Ok::<_, Error>)

View file

@ -172,7 +172,6 @@ async fn state_at_incoming_fork(
.short
.get_statekey_from_short(*k)
.map_ok(|(ty, sk)| ((ty, sk), id.clone()))
.map_ok(|((ty, sk), id)| ((ty, sk.as_str().to_owned()), id))
})
.ready_filter_map(Result::ok)
.collect()

View file

@ -3,7 +3,7 @@ use std::{borrow::Borrow, collections::BTreeMap, iter::once, sync::Arc, time::In
use conduwuit::{
debug, debug_info, err, implement, state_res, trace,
utils::stream::{BroadbandExt, ReadyExt},
warn, Err, EventTypeExt, PduEvent, Result,
warn, Err, EventTypeExt, PduEvent, Result, StateKey,
};
use futures::{future::ready, FutureExt, StreamExt};
use ruma::{events::StateEventType, CanonicalJsonValue, RoomId, ServerName};
@ -71,8 +71,8 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu(
debug!("Performing auth check");
// 11. Check the auth of the event passes based on the state of the event
let state_fetch_state = &state_at_incoming_event;
let state_fetch = |k: &'static StateEventType, s: String| async move {
let shortstatekey = self.services.short.get_shortstatekey(k, &s).await.ok()?;
let state_fetch = |k: StateEventType, s: StateKey| async move {
let shortstatekey = self.services.short.get_shortstatekey(&k, &s).await.ok()?;
let event_id = state_fetch_state.get(&shortstatekey)?;
self.services.timeline.get_pdu(event_id).await.ok()
@ -82,7 +82,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu(
&room_version,
&incoming_pdu,
None, // TODO: third party invite
|k, s| state_fetch(k, s.to_owned()),
|ty, sk| state_fetch(ty.clone(), sk.into()),
)
.await
.map_err(|e| err!(Request(Forbidden("Auth check failed: {e:?}"))))?;
@ -104,7 +104,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu(
)
.await?;
let state_fetch = |k: &'static StateEventType, s: &str| {
let state_fetch = |k: &StateEventType, s: &str| {
let key = k.with_state_key(s);
ready(auth_events.get(&key).cloned())
};

View file

@ -747,7 +747,7 @@ impl Service {
};
let auth_fetch = |k: &StateEventType, s: &str| {
let key = (k.clone(), s.to_owned());
let key = (k.clone(), s.into());
ready(auth_events.get(&key))
};