optimize with SmallString; consolidate related re-exports

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-02-08 00:16:37 +00:00 committed by strawberry
parent ecc9099127
commit b872f8e593
39 changed files with 113 additions and 96 deletions

View file

@ -47,7 +47,6 @@ zstd_compression = [
blurhashing = ["dep:image","dep:blurhash"]
[dependencies]
arrayvec.workspace = true
async-trait.workspace = true
base64.workspace = true
bytes.workspace = true
@ -75,7 +74,6 @@ serde_json.workspace = true
serde.workspace = true
serde_yaml.workspace = true
sha2.workspace = true
smallvec.workspace = true
termimad.workspace = true
termimad.optional = true
tokio.workspace = true

View file

@ -507,8 +507,10 @@ async fn fix_referencedevents_missing_sep(services: &Services) -> Result {
}
async fn fix_readreceiptid_readreceipt_duplicates(services: &Services) -> Result {
use conduwuit::arrayvec::ArrayString;
use ruma::identifiers_validation::MAX_BYTES;
type ArrayId = arrayvec::ArrayString<MAX_BYTES>;
type ArrayId = ArrayString<MAX_BYTES>;
type Key<'a> = (&'a RoomId, u64, &'a UserId);
warn!("Fixing undeleted entries in readreceiptid_readreceipt...");

View file

@ -1,7 +1,7 @@
use std::{net::IpAddr, sync::Arc, time::SystemTime};
use arrayvec::ArrayVec;
use conduwuit::{
arrayvec::ArrayVec,
at, err, implement,
utils::{math::Expected, rand, stream::TryIgnore},
Result,

View file

@ -4,8 +4,7 @@ use std::{
net::{IpAddr, SocketAddr},
};
use arrayvec::ArrayString;
use conduwuit::utils::math::Expected;
use conduwuit::{arrayvec::ArrayString, utils::math::Expected};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]

View file

@ -6,8 +6,7 @@ mod tests;
use std::sync::Arc;
use arrayvec::ArrayString;
use conduwuit::{utils::MutexMap, Result, Server};
use conduwuit::{arrayvec::ArrayString, utils::MutexMap, Result, Server};
use self::{cache::Cache, dns::Resolver};
use crate::{client, Dep};

View file

@ -6,10 +6,8 @@ use std::{
use conduwuit::{debug, debug_info, err, implement, trace, warn, Err, Error, PduEvent, Result};
use futures::{future::ready, TryFutureExt};
use ruma::{
api::client::error::ErrorKind,
events::StateEventType,
state_res::{self, EventTypeExt},
CanonicalJsonObject, CanonicalJsonValue, EventId, RoomId, ServerName,
api::client::error::ErrorKind, events::StateEventType, state_res, CanonicalJsonObject,
CanonicalJsonValue, EventId, RoomId, ServerName,
};
use super::{check_room_id, get_room_version_id, to_room_version};
@ -123,7 +121,7 @@ pub(super) async fn handle_outlier_pdu<'a>(
// The original create event must be in the auth events
if !matches!(
auth_events
.get(&(StateEventType::RoomCreate, String::new()))
.get(&(StateEventType::RoomCreate, String::new().into()))
.map(AsRef::as_ref),
Some(_) | None
) {
@ -134,7 +132,7 @@ pub(super) async fn handle_outlier_pdu<'a>(
}
let state_fetch = |ty: &'static StateEventType, sk: &str| {
let key = ty.with_state_key(sk);
let key = (ty.to_owned(), sk.into());
ready(auth_events.get(&key))
};

View file

@ -64,6 +64,7 @@ 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,6 +172,7 @@ 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

@ -1,7 +1,7 @@
use std::{mem::size_of, sync::Arc};
use arrayvec::ArrayVec;
use conduwuit::{
arrayvec::ArrayVec,
result::LogErr,
utils::{
stream::{TryIgnore, WidebandExt},

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use arrayvec::ArrayVec;
use conduwuit::{
arrayvec::ArrayVec,
implement,
utils::{
set,

View file

@ -1,7 +1,7 @@
use std::{borrow::Borrow, fmt::Debug, mem::size_of_val, sync::Arc};
pub use conduwuit::pdu::{ShortEventId, ShortId, ShortRoomId};
use conduwuit::{err, implement, utils, utils::IterStream, Result};
pub use conduwuit::pdu::{ShortEventId, ShortId, ShortRoomId, ShortStateKey};
use conduwuit::{err, implement, utils, utils::IterStream, Result, StateKey};
use database::{Deserialized, Get, Map, Qry};
use futures::{Stream, StreamExt};
use ruma::{events::StateEventType, EventId, RoomId};
@ -28,7 +28,6 @@ struct Services {
}
pub type ShortStateHash = ShortId;
pub type ShortStateKey = ShortId;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
@ -181,7 +180,7 @@ where
pub async fn get_statekey_from_short(
&self,
shortstatekey: ShortStateKey,
) -> Result<(StateEventType, String)> {
) -> Result<(StateEventType, StateKey)> {
const BUFSIZE: usize = size_of::<ShortStateKey>();
self.db
@ -200,7 +199,7 @@ pub async fn get_statekey_from_short(
pub fn multi_get_statekey_from_short<'a, S>(
&'a self,
shortstatekey: S,
) -> impl Stream<Item = Result<(StateEventType, String)>> + Send + 'a
) -> impl Stream<Item = Result<(StateEventType, StateKey)>> + Send + 'a
where
S: Stream<Item = ShortStateKey> + Send + 'a,
{

View file

@ -1,6 +1,6 @@
use std::borrow::Borrow;
use conduwuit::{err, implement, PduEvent, Result};
use conduwuit::{err, implement, PduEvent, Result, StateKey};
use futures::{Stream, StreamExt, TryFutureExt};
use ruma::{events::StateEventType, EventId, RoomId};
use serde::Deserialize;
@ -27,7 +27,7 @@ where
pub fn room_state_full<'a>(
&'a self,
room_id: &'a RoomId,
) -> impl Stream<Item = Result<((StateEventType, String), PduEvent)>> + Send + 'a {
) -> impl Stream<Item = Result<((StateEventType, StateKey), PduEvent)>> + Send + 'a {
self.services
.state
.get_room_shortstatehash(room_id)

View file

@ -6,7 +6,7 @@ use conduwuit::{
result::FlatOk,
stream::{BroadbandExt, IterStream, ReadyExt, TryExpect},
},
PduEvent, Result,
PduEvent, Result, StateKey,
};
use database::Deserialized;
use futures::{future::try_join, pin_mut, FutureExt, Stream, StreamExt, TryFutureExt};
@ -192,7 +192,7 @@ pub fn state_keys_with_ids<'a, Id>(
&'a self,
shortstatehash: ShortStateHash,
event_type: &'a StateEventType,
) -> impl Stream<Item = (String, Id)> + Send + 'a
) -> impl Stream<Item = (StateKey, Id)> + Send + 'a
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
<Id as ToOwned>::Owned: Borrow<EventId>,
@ -200,7 +200,7 @@ where
let state_keys_with_short_ids = self
.state_keys_with_shortids(shortstatehash, event_type)
.unzip()
.map(|(ssks, sids): (Vec<String>, Vec<u64>)| (ssks, sids))
.map(|(ssks, sids): (Vec<StateKey>, Vec<u64>)| (ssks, sids))
.shared();
let state_keys = state_keys_with_short_ids
@ -230,7 +230,7 @@ pub fn state_keys_with_shortids<'a>(
&'a self,
shortstatehash: ShortStateHash,
event_type: &'a StateEventType,
) -> impl Stream<Item = (String, ShortEventId)> + Send + 'a {
) -> impl Stream<Item = (StateKey, ShortEventId)> + Send + 'a {
let short_ids = self
.state_full_shortids(shortstatehash)
.expect_ok()
@ -267,7 +267,7 @@ pub fn state_keys<'a>(
&'a self,
shortstatehash: ShortStateHash,
event_type: &'a StateEventType,
) -> impl Stream<Item = String> + Send + 'a {
) -> impl Stream<Item = StateKey> + Send + 'a {
let short_ids = self
.state_full_shortids(shortstatehash)
.expect_ok()
@ -314,7 +314,7 @@ pub fn state_added(
pub fn state_full(
&self,
shortstatehash: ShortStateHash,
) -> impl Stream<Item = ((StateEventType, String), PduEvent)> + Send + '_ {
) -> impl Stream<Item = ((StateEventType, StateKey), PduEvent)> + Send + '_ {
self.state_full_pdus(shortstatehash)
.ready_filter_map(|pdu| {
Some(((pdu.kind.to_string().into(), pdu.state_key.clone()?), pdu))

View file

@ -175,7 +175,7 @@ pub async fn user_can_invite(
.timeline
.create_hash_and_sign_event(
PduBuilder::state(
target_user.into(),
target_user.as_str(),
&RoomMemberEventContent::new(MembershipState::Invite),
),
sender,

View file

@ -5,8 +5,8 @@ use std::{
sync::{Arc, Mutex},
};
use arrayvec::ArrayVec;
use conduwuit::{
arrayvec::ArrayVec,
at, checked, err, expected, utils,
utils::{bytes, math::usize_from_f64, stream::IterStream},
Result,

View file

@ -38,7 +38,7 @@ use ruma::{
push::{Action, Ruleset, Tweak},
state_res::{self, Event, RoomVersion},
uint, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId,
OwnedServerName, OwnedUserId, RoomId, RoomVersionId, ServerName, UserId,
OwnedServerName, RoomId, RoomVersionId, ServerName, UserId,
};
use serde::Deserialize;
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
@ -387,10 +387,10 @@ impl Service {
if pdu.kind == TimelineEventType::RoomMember {
if let Some(state_key) = &pdu.state_key {
let target_user_id = OwnedUserId::parse(state_key)?;
let target_user_id = UserId::parse(state_key)?;
if self.services.users.is_active_local(&target_user_id).await {
push_target.insert(target_user_id);
if self.services.users.is_active_local(target_user_id).await {
push_target.insert(target_user_id.to_owned());
}
}
}

View file

@ -13,6 +13,7 @@ use std::{
use async_trait::async_trait;
use conduwuit::{
debug, debug_warn, err, error,
smallvec::SmallVec,
utils::{available_parallelism, math::usize_from_u64_truncated, ReadyExt, TryReadyExt},
warn, Result, Server,
};
@ -21,7 +22,6 @@ use ruma::{
api::{appservice::Registration, OutgoingRequest},
RoomId, ServerName, UserId,
};
use smallvec::SmallVec;
use tokio::{task, task::JoinSet};
use self::data::Data;