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

@ -14,7 +14,7 @@ use conduwuit::{
result::FlatOk,
state_res, trace,
utils::{self, shuffle, IterStream, ReadyExt},
warn, Err, PduEvent, Result,
warn, Err, PduEvent, Result, StateKey,
};
use futures::{join, FutureExt, StreamExt, TryFutureExt};
use ruma::{
@ -1151,8 +1151,8 @@ async fn join_room_by_id_helper_remote(
debug!("Running send_join auth check");
let fetch_state = &state;
let state_fetch = |k: &'static StateEventType, s: String| async move {
let shortstatekey = services.rooms.short.get_shortstatekey(k, &s).await.ok()?;
let state_fetch = |k: StateEventType, s: StateKey| async move {
let shortstatekey = services.rooms.short.get_shortstatekey(&k, &s).await.ok()?;
let event_id = fetch_state.get(&shortstatekey)?;
services.rooms.timeline.get_pdu(event_id).await.ok()
@ -1162,7 +1162,7 @@ async fn join_room_by_id_helper_remote(
&state_res::RoomVersion::new(&room_version_id)?,
&parsed_join_pdu,
None, // TODO: third party invite
|k, s| state_fetch(k, s.to_owned()),
|k, s| state_fetch(k.clone(), s.into()),
)
.await
.map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?;

View file

@ -395,9 +395,12 @@ pub(crate) async fn sync_events_v4_route(
.map_or(10, usize_from_u64_truncated)
.min(100);
todo_room
.0
.extend(list.room_details.required_state.iter().cloned());
todo_room.0.extend(
list.room_details
.required_state
.iter()
.map(|(ty, sk)| (ty.clone(), sk.as_str().into())),
);
todo_room.1 = todo_room.1.max(limit);
// 0 means unknown because it got out of date
@ -449,7 +452,11 @@ pub(crate) async fn sync_events_v4_route(
.map_or(10, usize_from_u64_truncated)
.min(100);
todo_room.0.extend(room.required_state.iter().cloned());
todo_room.0.extend(
room.required_state
.iter()
.map(|(ty, sk)| (ty.clone(), sk.as_str().into())),
);
todo_room.1 = todo_room.1.max(limit);
// 0 means unknown because it got out of date
todo_room.2 = todo_room.2.min(

View file

@ -223,7 +223,11 @@ async fn fetch_subscriptions(
let limit: UInt = room.timeline_limit;
todo_room.0.extend(room.required_state.iter().cloned());
todo_room.0.extend(
room.required_state
.iter()
.map(|(ty, sk)| (ty.clone(), sk.as_str().into())),
);
todo_room.1 = todo_room.1.max(usize_from_ruma(limit));
// 0 means unknown because it got out of date
todo_room.2 = todo_room.2.min(
@ -303,9 +307,12 @@ async fn handle_lists<'a>(
let limit: usize = usize_from_ruma(list.room_details.timeline_limit).min(100);
todo_room
.0
.extend(list.room_details.required_state.iter().cloned());
todo_room.0.extend(
list.room_details
.required_state
.iter()
.map(|(ty, sk)| (ty.clone(), sk.as_str().into())),
);
todo_room.1 = todo_room.1.max(limit);
// 0 means unknown because it got out of date