Simplify types, mitigate expansion; eliminate unnecessary move.
Further simplify future::BoolExt toward type expansion mitigation. Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -7,7 +7,7 @@ use tuwunel_core::{
|
|||||||
is_equal_to, is_true,
|
is_equal_to, is_true,
|
||||||
utils::{
|
utils::{
|
||||||
BoolExt, FutureBoolExt, IterStream, ReadyExt,
|
BoolExt, FutureBoolExt, IterStream, ReadyExt,
|
||||||
future::{OptionExt, ReadyEqExt},
|
future::{self, OptionExt, ReadyEqExt},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -115,19 +115,16 @@ pub(super) async fn filter_room(
|
|||||||
})
|
})
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
match_encrypted
|
future::and7(
|
||||||
.is_none_or(is_true!())
|
match_invite.is_none_or(is_true!()),
|
||||||
.and3(
|
match_encrypted.is_none_or(is_true!()),
|
||||||
match_invite.is_none_or(is_true!()),
|
match_direct.is_none_or(is_true!()),
|
||||||
match_direct.is_none_or(is_true!()),
|
match_direct_member.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!()),
|
||||||
.and3(
|
match_room_tag.is_none_or(is_true!()),
|
||||||
match_space_child.is_none_or(is_true!()),
|
)
|
||||||
match_room_type.is_none_or(is_true!()),
|
.await
|
||||||
match_room_tag.is_none_or(is_true!()),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "filter_meta", level = "trace", skip_all)]
|
#[tracing::instrument(name = "filter_meta", level = "trace", skip_all)]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#![type_length_limit = "589824"] //TODO: REDUCE ME
|
#![type_length_limit = "262144"] //TODO: REDUCE ME
|
||||||
#![allow(clippy::toplevel_ref_arg)]
|
#![allow(clippy::toplevel_ref_arg)]
|
||||||
|
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//! Extended external extensions to futures::FutureExt
|
//! Extended external extensions to futures::FutureExt
|
||||||
|
#![allow(clippy::many_single_char_names, clippy::impl_trait_in_params)]
|
||||||
|
|
||||||
use std::marker::Unpin;
|
use std::marker::Unpin;
|
||||||
|
|
||||||
@@ -16,8 +17,6 @@ pub trait BoolExt
|
|||||||
where
|
where
|
||||||
Self: Future<Output = bool> + Send,
|
Self: Future<Output = bool> + Send,
|
||||||
{
|
{
|
||||||
type Result;
|
|
||||||
|
|
||||||
fn or<B>(self, b: B) -> impl Future<Output = bool> + Send
|
fn or<B>(self, b: B) -> impl Future<Output = bool> + Send
|
||||||
where
|
where
|
||||||
B: Future<Output = bool> + Send + Unpin,
|
B: Future<Output = bool> + Send + Unpin,
|
||||||
@@ -46,15 +45,11 @@ impl<Fut> BoolExt for Fut
|
|||||||
where
|
where
|
||||||
Fut: Future<Output = bool> + Send,
|
Fut: Future<Output = bool> + Send,
|
||||||
{
|
{
|
||||||
type Result = crate::Result<(), ()>;
|
|
||||||
|
|
||||||
fn or<B>(self, b: B) -> impl Future<Output = bool> + Send
|
fn or<B>(self, b: B) -> impl Future<Output = bool> + Send
|
||||||
where
|
where
|
||||||
B: Future<Output = bool> + Send + Unpin,
|
B: Future<Output = bool> + Send + Unpin,
|
||||||
Self: Sized + 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())
|
select_ok([Left(self.map(test)), Right(b.map(test))]).map(|res| res.is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,8 +58,6 @@ where
|
|||||||
B: Future<Output = bool> + Send,
|
B: Future<Output = bool> + Send,
|
||||||
Self: Sized,
|
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())
|
try_join(self.map(test), b.map(test)).map(|res| res.is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +67,6 @@ where
|
|||||||
C: Future<Output = bool> + Send,
|
C: Future<Output = bool> + Send,
|
||||||
Self: Sized,
|
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())
|
try_join3(self.map(test), b.map(test), c.map(test)).map(|res| res.is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +77,6 @@ where
|
|||||||
D: Future<Output = bool> + Send,
|
D: Future<Output = bool> + Send,
|
||||||
Self: Sized,
|
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())
|
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<Item = F> + Send,
|
I: Iterator<Item = F> + Send,
|
||||||
F: Future<Output = bool> + Send,
|
F: Future<Output = bool> + Send,
|
||||||
{
|
{
|
||||||
type Result = crate::Result<(), ()>;
|
let args = args.map(|a| a.map(test));
|
||||||
|
|
||||||
let args = args.map(|a| a.map(|a| a.ok_or(Result::Err(()))));
|
|
||||||
|
|
||||||
try_join_all(args).map(|res| res.is_ok())
|
try_join_all(args).map(|res| res.is_ok())
|
||||||
}
|
}
|
||||||
@@ -109,9 +96,51 @@ where
|
|||||||
I: Iterator<Item = F> + Send,
|
I: Iterator<Item = F> + Send,
|
||||||
F: Future<Output = bool> + Send + Unpin,
|
F: Future<Output = bool> + Send + Unpin,
|
||||||
{
|
{
|
||||||
type Result = crate::Result<(), ()>;
|
let args = args.map(|a| a.map(test));
|
||||||
|
|
||||||
let args = args.map(|a| a.map(|a| a.ok_or(Result::Err(()))));
|
|
||||||
|
|
||||||
select_ok(args).map(|res| res.is_ok())
|
select_ok(args).map(|res| res.is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn and4(
|
||||||
|
a: impl Future<Output = bool> + Send,
|
||||||
|
b: impl Future<Output = bool> + Send,
|
||||||
|
c: impl Future<Output = bool> + Send,
|
||||||
|
d: impl Future<Output = bool> + Send,
|
||||||
|
) -> impl Future<Output = bool> + Send {
|
||||||
|
a.and3(b, c, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn and5(
|
||||||
|
a: impl Future<Output = bool> + Send,
|
||||||
|
b: impl Future<Output = bool> + Send,
|
||||||
|
c: impl Future<Output = bool> + Send,
|
||||||
|
d: impl Future<Output = bool> + Send,
|
||||||
|
e: impl Future<Output = bool> + Send,
|
||||||
|
) -> impl Future<Output = bool> + Send {
|
||||||
|
a.and2(b, c).and2(d, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn and6(
|
||||||
|
a: impl Future<Output = bool> + Send,
|
||||||
|
b: impl Future<Output = bool> + Send,
|
||||||
|
c: impl Future<Output = bool> + Send,
|
||||||
|
d: impl Future<Output = bool> + Send,
|
||||||
|
e: impl Future<Output = bool> + Send,
|
||||||
|
f: impl Future<Output = bool> + Send,
|
||||||
|
) -> impl Future<Output = bool> + Send {
|
||||||
|
a.and3(b, c, d).and2(e, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn and7(
|
||||||
|
a: impl Future<Output = bool> + Send,
|
||||||
|
b: impl Future<Output = bool> + Send,
|
||||||
|
c: impl Future<Output = bool> + Send,
|
||||||
|
d: impl Future<Output = bool> + Send,
|
||||||
|
e: impl Future<Output = bool> + Send,
|
||||||
|
f: impl Future<Output = bool> + Send,
|
||||||
|
g: impl Future<Output = bool> + Send,
|
||||||
|
) -> impl Future<Output = bool> + Send {
|
||||||
|
a.and3(b, c, d).and3(e, f, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test(test: bool) -> crate::Result<(), ()> { test.ok_or(()) }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ mod option_stream;
|
|||||||
mod ready_eq_ext;
|
mod ready_eq_ext;
|
||||||
mod try_ext_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 ext_ext::ExtExt;
|
||||||
pub use option_ext::OptionExt;
|
pub use option_ext::OptionExt;
|
||||||
pub use option_stream::OptionStream;
|
pub use option_stream::OptionStream;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use ruma::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::{Mutex, MutexGuard};
|
use tokio::sync::{Mutex, MutexGuard};
|
||||||
use tuwunel_core::{
|
use tuwunel_core::{
|
||||||
Err, Error, Event, PduEvent, Result, implement,
|
Err, Error, Event, Result, implement,
|
||||||
utils::{
|
utils::{
|
||||||
IterStream,
|
IterStream,
|
||||||
future::{BoolExt, TryExtExt},
|
future::{BoolExt, TryExtExt},
|
||||||
@@ -513,12 +513,12 @@ async fn cache_insert(
|
|||||||
fn get_space_child_events<'a>(
|
fn get_space_child_events<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
room_id: &'a RoomId,
|
room_id: &'a RoomId,
|
||||||
) -> impl Stream<Item = PduEvent> + Send + 'a {
|
) -> impl Stream<Item = impl Event> + Send + 'a {
|
||||||
self.services
|
self.services
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.room_state_keys_with_ids(room_id, &StateEventType::SpaceChild)
|
.room_state_keys_with_ids(room_id, &StateEventType::SpaceChild)
|
||||||
.ready_filter_map(Result::ok)
|
.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
|
self.services
|
||||||
.timeline
|
.timeline
|
||||||
.get_pdu(&event_id)
|
.get_pdu(&event_id)
|
||||||
@@ -526,7 +526,7 @@ fn get_space_child_events<'a>(
|
|||||||
.ok()
|
.ok()
|
||||||
.await
|
.await
|
||||||
})
|
})
|
||||||
.ready_filter_map(move |(state_key, pdu)| {
|
.ready_filter_map(|(state_key, pdu)| {
|
||||||
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>() {
|
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>() {
|
||||||
if content.via.is_empty() {
|
if content.via.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use std::borrow::Borrow;
|
|
||||||
|
|
||||||
use futures::{Stream, StreamExt, TryFutureExt};
|
use futures::{Stream, StreamExt, TryFutureExt};
|
||||||
use ruma::{EventId, RoomId, events::StateEventType};
|
use ruma::{OwnedEventId, RoomId, events::StateEventType};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tuwunel_core::{
|
use tuwunel_core::{
|
||||||
Result, err, implement,
|
Result, err, implement,
|
||||||
@@ -82,16 +80,12 @@ pub fn room_state_full_pdus<'a>(
|
|||||||
/// `state_key`).
|
/// `state_key`).
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
#[tracing::instrument(skip(self), level = "debug")]
|
#[tracing::instrument(skip(self), level = "debug")]
|
||||||
pub async fn room_state_get_id<Id>(
|
pub async fn room_state_get_id(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_type: &StateEventType,
|
event_type: &StateEventType,
|
||||||
state_key: &str,
|
state_key: &str,
|
||||||
) -> Result<Id>
|
) -> Result<OwnedEventId> {
|
||||||
where
|
|
||||||
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned,
|
|
||||||
<Id as ToOwned>::Owned: Borrow<EventId>,
|
|
||||||
{
|
|
||||||
self.services
|
self.services
|
||||||
.state
|
.state
|
||||||
.get_room_shortstatehash(room_id)
|
.get_room_shortstatehash(room_id)
|
||||||
@@ -103,15 +97,11 @@ where
|
|||||||
/// `event_id` from the current state.
|
/// `event_id` from the current state.
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
#[tracing::instrument(skip(self), level = "debug")]
|
#[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,
|
&'a self,
|
||||||
room_id: &'a RoomId,
|
room_id: &'a RoomId,
|
||||||
event_type: &'a StateEventType,
|
event_type: &'a StateEventType,
|
||||||
) -> impl Stream<Item = Result<(StateKey, Id)>> + Send + 'a
|
) -> impl Stream<Item = Result<(StateKey, OwnedEventId)>> + Send + 'a {
|
||||||
where
|
|
||||||
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
|
|
||||||
<Id as ToOwned>::Owned: Borrow<EventId>,
|
|
||||||
{
|
|
||||||
self.services
|
self.services
|
||||||
.state
|
.state
|
||||||
.get_room_shortstatehash(room_id)
|
.get_room_shortstatehash(room_id)
|
||||||
|
|||||||
@@ -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 futures::{FutureExt, Stream, StreamExt, TryFutureExt, future::try_join, pin_mut};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
EventId, OwnedEventId, UserId,
|
OwnedEventId, UserId,
|
||||||
events::{
|
events::{
|
||||||
StateEventType,
|
StateEventType,
|
||||||
room::member::{MembershipState, RoomMemberEventContent},
|
room::member::{MembershipState, RoomMemberEventContent},
|
||||||
@@ -138,16 +138,12 @@ pub async fn state_get(
|
|||||||
/// Returns a single EventId from `room_id` with key (`event_type`,
|
/// Returns a single EventId from `room_id` with key (`event_type`,
|
||||||
/// `state_key`).
|
/// `state_key`).
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
pub async fn state_get_id<Id>(
|
pub async fn state_get_id(
|
||||||
&self,
|
&self,
|
||||||
shortstatehash: ShortStateHash,
|
shortstatehash: ShortStateHash,
|
||||||
event_type: &StateEventType,
|
event_type: &StateEventType,
|
||||||
state_key: &str,
|
state_key: &str,
|
||||||
) -> Result<Id>
|
) -> Result<OwnedEventId> {
|
||||||
where
|
|
||||||
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned,
|
|
||||||
<Id as ToOwned>::Owned: Borrow<EventId>,
|
|
||||||
{
|
|
||||||
let shorteventid = self
|
let shorteventid = self
|
||||||
.state_get_shortid(shortstatehash, event_type, state_key)
|
.state_get_shortid(shortstatehash, event_type, state_key)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -209,15 +205,11 @@ pub fn state_type_pdus<'a>(
|
|||||||
/// Iterates the state_keys for an event_type in the state; current state
|
/// Iterates the state_keys for an event_type in the state; current state
|
||||||
/// event_id included.
|
/// event_id included.
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
pub fn state_keys_with_ids<'a, Id>(
|
pub fn state_keys_with_ids<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
shortstatehash: ShortStateHash,
|
shortstatehash: ShortStateHash,
|
||||||
event_type: &'a StateEventType,
|
event_type: &'a StateEventType,
|
||||||
) -> impl Stream<Item = (StateKey, Id)> + Send + 'a
|
) -> impl Stream<Item = (StateKey, OwnedEventId)> + Send + 'a {
|
||||||
where
|
|
||||||
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
|
|
||||||
<Id as ToOwned>::Owned: Borrow<EventId>,
|
|
||||||
{
|
|
||||||
let state_keys_with_short_ids = self
|
let state_keys_with_short_ids = self
|
||||||
.state_keys_with_shortids(shortstatehash, event_type)
|
.state_keys_with_shortids(shortstatehash, event_type)
|
||||||
.unzip()
|
.unzip()
|
||||||
@@ -371,14 +363,10 @@ pub fn state_full_pdus(
|
|||||||
/// Builds a StateMap by iterating over all keys that start
|
/// Builds a StateMap by iterating over all keys that start
|
||||||
/// with state_hash, this gives the full state for the given state_hash.
|
/// with state_hash, this gives the full state for the given state_hash.
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
pub fn state_full_ids<'a, Id>(
|
pub fn state_full_ids(
|
||||||
&'a self,
|
&self,
|
||||||
shortstatehash: ShortStateHash,
|
shortstatehash: ShortStateHash,
|
||||||
) -> impl Stream<Item = (ShortStateKey, Id)> + Send + 'a
|
) -> impl Stream<Item = (ShortStateKey, OwnedEventId)> + Send + '_ {
|
||||||
where
|
|
||||||
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned + 'a,
|
|
||||||
<Id as ToOwned>::Owned: Borrow<EventId>,
|
|
||||||
{
|
|
||||||
let shortids = self
|
let shortids = self
|
||||||
.state_full_shortids(shortstatehash)
|
.state_full_shortids(shortstatehash)
|
||||||
.ignore_err()
|
.ignore_err()
|
||||||
|
|||||||
Reference in New Issue
Block a user