diff --git a/src/api/client/sync/v5/filter.rs b/src/api/client/sync/v5/filter.rs index 26008cfd..31292621 100644 --- a/src/api/client/sync/v5/filter.rs +++ b/src/api/client/sync/v5/filter.rs @@ -7,7 +7,7 @@ use tuwunel_core::{ is_equal_to, is_true, utils::{ BoolExt, FutureBoolExt, IterStream, ReadyExt, - future::{OptionExt, ReadyEqExt}, + future::{self, OptionExt, ReadyEqExt}, }, }; @@ -115,19 +115,16 @@ pub(super) async fn filter_room( }) .into(); - match_encrypted - .is_none_or(is_true!()) - .and3( - match_invite.is_none_or(is_true!()), - match_direct.is_none_or(is_true!()), - match_direct_member.is_none_or(is_true!()), - ) - .and3( - match_space_child.is_none_or(is_true!()), - match_room_type.is_none_or(is_true!()), - match_room_tag.is_none_or(is_true!()), - ) - .await + future::and7( + match_invite.is_none_or(is_true!()), + match_encrypted.is_none_or(is_true!()), + match_direct.is_none_or(is_true!()), + match_direct_member.is_none_or(is_true!()), + match_space_child.is_none_or(is_true!()), + match_room_type.is_none_or(is_true!()), + match_room_tag.is_none_or(is_true!()), + ) + .await } #[tracing::instrument(name = "filter_meta", level = "trace", skip_all)] diff --git a/src/api/mod.rs b/src/api/mod.rs index 344c4300..0409b2d8 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,4 +1,4 @@ -#![type_length_limit = "589824"] //TODO: REDUCE ME +#![type_length_limit = "262144"] //TODO: REDUCE ME #![allow(clippy::toplevel_ref_arg)] pub mod client; diff --git a/src/core/utils/future/bool_ext.rs b/src/core/utils/future/bool_ext.rs index c24a4a16..3bae174f 100644 --- a/src/core/utils/future/bool_ext.rs +++ b/src/core/utils/future/bool_ext.rs @@ -1,4 +1,5 @@ //! Extended external extensions to futures::FutureExt +#![allow(clippy::many_single_char_names, clippy::impl_trait_in_params)] use std::marker::Unpin; @@ -16,8 +17,6 @@ pub trait BoolExt where Self: Future + Send, { - type Result; - fn or(self, b: B) -> impl Future + Send where B: Future + Send + Unpin, @@ -46,15 +45,11 @@ impl BoolExt for Fut where Fut: Future + Send, { - type Result = crate::Result<(), ()>; - fn or(self, b: B) -> impl Future + Send where B: Future + Send + Unpin, Self: Sized + Unpin, { - let test = |test: bool| test.ok_or(Self::Result::Err(())); - select_ok([Left(self.map(test)), Right(b.map(test))]).map(|res| res.is_ok()) } @@ -63,8 +58,6 @@ where B: Future + Send, Self: Sized, { - let test = |test: bool| test.ok_or(Self::Result::Err(())); - try_join(self.map(test), b.map(test)).map(|res| res.is_ok()) } @@ -74,8 +67,6 @@ where C: Future + Send, Self: Sized, { - let test = |test: bool| test.ok_or(Self::Result::Err(())); - try_join3(self.map(test), b.map(test), c.map(test)).map(|res| res.is_ok()) } @@ -86,8 +77,6 @@ where D: Future + Send, Self: Sized, { - let test = |test: bool| test.ok_or(Self::Result::Err(())); - try_join4(self.map(test), b.map(test), c.map(test), d.map(test)).map(|res| res.is_ok()) } } @@ -97,9 +86,7 @@ where I: Iterator + Send, F: Future + Send, { - type Result = crate::Result<(), ()>; - - let args = args.map(|a| a.map(|a| a.ok_or(Result::Err(())))); + let args = args.map(|a| a.map(test)); try_join_all(args).map(|res| res.is_ok()) } @@ -109,9 +96,51 @@ where I: Iterator + Send, F: Future + Send + Unpin, { - type Result = crate::Result<(), ()>; - - let args = args.map(|a| a.map(|a| a.ok_or(Result::Err(())))); + let args = args.map(|a| a.map(test)); select_ok(args).map(|res| res.is_ok()) } + +pub fn and4( + a: impl Future + Send, + b: impl Future + Send, + c: impl Future + Send, + d: impl Future + Send, +) -> impl Future + Send { + a.and3(b, c, d) +} + +pub fn and5( + a: impl Future + Send, + b: impl Future + Send, + c: impl Future + Send, + d: impl Future + Send, + e: impl Future + Send, +) -> impl Future + Send { + a.and2(b, c).and2(d, e) +} + +pub fn and6( + a: impl Future + Send, + b: impl Future + Send, + c: impl Future + Send, + d: impl Future + Send, + e: impl Future + Send, + f: impl Future + Send, +) -> impl Future + Send { + a.and3(b, c, d).and2(e, f) +} + +pub fn and7( + a: impl Future + Send, + b: impl Future + Send, + c: impl Future + Send, + d: impl Future + Send, + e: impl Future + Send, + f: impl Future + Send, + g: impl Future + Send, +) -> impl Future + Send { + a.and3(b, c, d).and3(e, f, g) +} + +fn test(test: bool) -> crate::Result<(), ()> { test.ok_or(()) } diff --git a/src/core/utils/future/mod.rs b/src/core/utils/future/mod.rs index d896e66d..c80ccdd6 100644 --- a/src/core/utils/future/mod.rs +++ b/src/core/utils/future/mod.rs @@ -5,7 +5,7 @@ mod option_stream; mod ready_eq_ext; mod try_ext_ext; -pub use bool_ext::{BoolExt, and, or}; +pub use bool_ext::{BoolExt, and, and4, and5, and6, and7, or}; pub use ext_ext::ExtExt; pub use option_ext::OptionExt; pub use option_stream::OptionStream; diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 9603267d..a87dcccd 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -22,7 +22,7 @@ use ruma::{ }; use tokio::sync::{Mutex, MutexGuard}; use tuwunel_core::{ - Err, Error, Event, PduEvent, Result, implement, + Err, Error, Event, Result, implement, utils::{ IterStream, future::{BoolExt, TryExtExt}, @@ -513,12 +513,12 @@ async fn cache_insert( fn get_space_child_events<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { self.services .state_accessor .room_state_keys_with_ids(room_id, &StateEventType::SpaceChild) .ready_filter_map(Result::ok) - .broad_filter_map(async move |(state_key, event_id): (_, OwnedEventId)| { + .broad_filter_map(async |(state_key, event_id): (_, OwnedEventId)| { self.services .timeline .get_pdu(&event_id) @@ -526,7 +526,7 @@ fn get_space_child_events<'a>( .ok() .await }) - .ready_filter_map(move |(state_key, pdu)| { + .ready_filter_map(|(state_key, pdu)| { if let Ok(content) = pdu.get_content::() { if content.via.is_empty() { return None; diff --git a/src/service/rooms/state_accessor/room_state.rs b/src/service/rooms/state_accessor/room_state.rs index 9e0dc024..dbb716a9 100644 --- a/src/service/rooms/state_accessor/room_state.rs +++ b/src/service/rooms/state_accessor/room_state.rs @@ -1,7 +1,5 @@ -use std::borrow::Borrow; - use futures::{Stream, StreamExt, TryFutureExt}; -use ruma::{EventId, RoomId, events::StateEventType}; +use ruma::{OwnedEventId, RoomId, events::StateEventType}; use serde::Deserialize; use tuwunel_core::{ Result, err, implement, @@ -82,16 +80,12 @@ pub fn room_state_full_pdus<'a>( /// `state_key`). #[implement(super::Service)] #[tracing::instrument(skip(self), level = "debug")] -pub async fn room_state_get_id( +pub async fn room_state_get_id( &self, room_id: &RoomId, event_type: &StateEventType, state_key: &str, -) -> Result -where - Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned, - ::Owned: Borrow, -{ +) -> Result { self.services .state .get_room_shortstatehash(room_id) @@ -103,15 +97,11 @@ where /// `event_id` from the current state. #[implement(super::Service)] #[tracing::instrument(skip(self), level = "debug")] -pub fn room_state_keys_with_ids<'a, Id>( +pub fn room_state_keys_with_ids<'a>( &'a self, room_id: &'a RoomId, event_type: &'a StateEventType, -) -> impl Stream> + Send + 'a -where - Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a, - ::Owned: Borrow, -{ +) -> impl Stream> + Send + 'a { self.services .state .get_room_shortstatehash(room_id) diff --git a/src/service/rooms/state_accessor/state.rs b/src/service/rooms/state_accessor/state.rs index 4621760c..ae5dc1a9 100644 --- a/src/service/rooms/state_accessor/state.rs +++ b/src/service/rooms/state_accessor/state.rs @@ -1,8 +1,8 @@ -use std::{borrow::Borrow, ops::Deref, sync::Arc}; +use std::{ops::Deref, sync::Arc}; use futures::{FutureExt, Stream, StreamExt, TryFutureExt, future::try_join, pin_mut}; use ruma::{ - EventId, OwnedEventId, UserId, + OwnedEventId, UserId, events::{ StateEventType, room::member::{MembershipState, RoomMemberEventContent}, @@ -138,16 +138,12 @@ pub async fn state_get( /// Returns a single EventId from `room_id` with key (`event_type`, /// `state_key`). #[implement(super::Service)] -pub async fn state_get_id( +pub async fn state_get_id( &self, shortstatehash: ShortStateHash, event_type: &StateEventType, state_key: &str, -) -> Result -where - Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned, - ::Owned: Borrow, -{ +) -> Result { let shorteventid = self .state_get_shortid(shortstatehash, event_type, state_key) .await?; @@ -209,15 +205,11 @@ pub fn state_type_pdus<'a>( /// Iterates the state_keys for an event_type in the state; current state /// event_id included. #[implement(super::Service)] -pub fn state_keys_with_ids<'a, Id>( +pub fn state_keys_with_ids<'a>( &'a self, shortstatehash: ShortStateHash, event_type: &'a StateEventType, -) -> impl Stream + Send + 'a -where - Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a, - ::Owned: Borrow, -{ +) -> impl Stream + Send + 'a { let state_keys_with_short_ids = self .state_keys_with_shortids(shortstatehash, event_type) .unzip() @@ -371,14 +363,10 @@ pub fn state_full_pdus( /// Builds a StateMap by iterating over all keys that start /// with state_hash, this gives the full state for the given state_hash. #[implement(super::Service)] -pub fn state_full_ids<'a, Id>( - &'a self, +pub fn state_full_ids( + &self, shortstatehash: ShortStateHash, -) -> impl Stream + Send + 'a -where - Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a, - ::Owned: Borrow, -{ +) -> impl Stream + Send + '_ { let shortids = self .state_full_shortids(shortstatehash) .ignore_err()