Database Refactor
combine service/users data w/ mod unit split sliding sync related out of service/users instrument database entry points remove increment crap from database interface de-wrap all database get() calls de-wrap all database insert() calls de-wrap all database remove() calls refactor database interface for async streaming add query key serializer for database implement Debug for result handle add query deserializer for database add deserialization trait for option handle start a stream utils suite de-wrap/asyncify/type-query count_one_time_keys() de-wrap/asyncify users count add admin query users command suite de-wrap/asyncify users exists de-wrap/partially asyncify user filter related asyncify/de-wrap users device/keys related asyncify/de-wrap user auth/misc related asyncify/de-wrap users blurhash asyncify/de-wrap account_data get; merge Data into Service partial asyncify/de-wrap uiaa; merge Data into Service partially asyncify/de-wrap transaction_ids get; merge Data into Service partially asyncify/de-wrap key_backups; merge Data into Service asyncify/de-wrap pusher service getters; merge Data into Service asyncify/de-wrap rooms alias getters/some iterators asyncify/de-wrap rooms directory getters/iterator partially asyncify/de-wrap rooms lazy-loading partially asyncify/de-wrap rooms metadata asyncify/dewrap rooms outlier asyncify/dewrap rooms pdu_metadata dewrap/partially asyncify rooms read receipt de-wrap rooms search service de-wrap/partially asyncify rooms user service partial de-wrap rooms state_compressor de-wrap rooms state_cache de-wrap room state et al de-wrap rooms timeline service additional users device/keys related de-wrap/asyncify sender asyncify services refactor database to TryFuture/TryStream refactor services for TryFuture/TryStream asyncify api handlers additional asyncification for admin module abstract stream related; support reverse streams additional stream conversions asyncify state-res related Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
6001014078
commit
946ca364e0
203 changed files with 12202 additions and 10709 deletions
20
src/core/utils/stream/cloned.rs
Normal file
20
src/core/utils/stream/cloned.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use std::clone::Clone;
|
||||
|
||||
use futures::{stream::Map, Stream, StreamExt};
|
||||
|
||||
pub trait Cloned<'a, T, S>
|
||||
where
|
||||
S: Stream<Item = &'a T>,
|
||||
T: Clone + 'a,
|
||||
{
|
||||
fn cloned(self) -> Map<S, fn(&T) -> T>;
|
||||
}
|
||||
|
||||
impl<'a, T, S> Cloned<'a, T, S> for S
|
||||
where
|
||||
S: Stream<Item = &'a T>,
|
||||
T: Clone + 'a,
|
||||
{
|
||||
#[inline]
|
||||
fn cloned(self) -> Map<S, fn(&T) -> T> { self.map(Clone::clone) }
|
||||
}
|
17
src/core/utils/stream/expect.rs
Normal file
17
src/core/utils/stream/expect.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use futures::{Stream, StreamExt, TryStream};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
pub trait TryExpect<'a, Item> {
|
||||
fn expect_ok(self) -> impl Stream<Item = Item> + Send + 'a;
|
||||
}
|
||||
|
||||
impl<'a, T, Item> TryExpect<'a, Item> for T
|
||||
where
|
||||
T: Stream<Item = Result<Item>> + TryStream + Send + 'a,
|
||||
{
|
||||
#[inline]
|
||||
fn expect_ok(self: T) -> impl Stream<Item = Item> + Send + 'a {
|
||||
self.map(|res| res.expect("stream expectation failure"))
|
||||
}
|
||||
}
|
21
src/core/utils/stream/ignore.rs
Normal file
21
src/core/utils/stream/ignore.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use futures::{future::ready, Stream, StreamExt, TryStream};
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
pub trait TryIgnore<'a, Item> {
|
||||
fn ignore_err(self) -> impl Stream<Item = Item> + Send + 'a;
|
||||
|
||||
fn ignore_ok(self) -> impl Stream<Item = Error> + Send + 'a;
|
||||
}
|
||||
|
||||
impl<'a, T, Item> TryIgnore<'a, Item> for T
|
||||
where
|
||||
T: Stream<Item = Result<Item>> + TryStream + Send + 'a,
|
||||
Item: Send + 'a,
|
||||
{
|
||||
#[inline]
|
||||
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a { self.filter_map(|res| ready(res.ok())) }
|
||||
|
||||
#[inline]
|
||||
fn ignore_ok(self: T) -> impl Stream<Item = Error> + Send + 'a { self.filter_map(|res| ready(res.err())) }
|
||||
}
|
27
src/core/utils/stream/iter_stream.rs
Normal file
27
src/core/utils/stream/iter_stream.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
use futures::{
|
||||
stream,
|
||||
stream::{Stream, TryStream},
|
||||
StreamExt,
|
||||
};
|
||||
|
||||
pub trait IterStream<I: IntoIterator + Send> {
|
||||
/// Convert an Iterator into a Stream
|
||||
fn stream(self) -> impl Stream<Item = <I as IntoIterator>::Item> + Send;
|
||||
|
||||
/// Convert an Iterator into a TryStream
|
||||
fn try_stream(self) -> impl TryStream<Ok = <I as IntoIterator>::Item, Error = crate::Error> + Send;
|
||||
}
|
||||
|
||||
impl<I> IterStream<I> for I
|
||||
where
|
||||
I: IntoIterator + Send,
|
||||
<I as IntoIterator>::IntoIter: Send,
|
||||
{
|
||||
#[inline]
|
||||
fn stream(self) -> impl Stream<Item = <I as IntoIterator>::Item> + Send { stream::iter(self) }
|
||||
|
||||
#[inline]
|
||||
fn try_stream(self) -> impl TryStream<Ok = <I as IntoIterator>::Item, Error = crate::Error> + Send {
|
||||
self.stream().map(Ok)
|
||||
}
|
||||
}
|
13
src/core/utils/stream/mod.rs
Normal file
13
src/core/utils/stream/mod.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
mod cloned;
|
||||
mod expect;
|
||||
mod ignore;
|
||||
mod iter_stream;
|
||||
mod ready;
|
||||
mod try_ready;
|
||||
|
||||
pub use cloned::Cloned;
|
||||
pub use expect::TryExpect;
|
||||
pub use ignore::TryIgnore;
|
||||
pub use iter_stream::IterStream;
|
||||
pub use ready::ReadyExt;
|
||||
pub use try_ready::TryReadyExt;
|
109
src/core/utils/stream/ready.rs
Normal file
109
src/core/utils/stream/ready.rs
Normal file
|
@ -0,0 +1,109 @@
|
|||
//! Synchronous combinator extensions to futures::Stream
|
||||
|
||||
use futures::{
|
||||
future::{ready, Ready},
|
||||
stream::{Any, Filter, FilterMap, Fold, ForEach, SkipWhile, Stream, StreamExt, TakeWhile},
|
||||
};
|
||||
|
||||
/// Synchronous combinators to augment futures::StreamExt. Most Stream
|
||||
/// combinators take asynchronous arguments, but often only simple predicates
|
||||
/// are required to steer a Stream like an Iterator. This suite provides a
|
||||
/// convenience to reduce boilerplate by de-cluttering non-async predicates.
|
||||
///
|
||||
/// This interface is not necessarily complete; feel free to add as-needed.
|
||||
pub trait ReadyExt<Item, S>
|
||||
where
|
||||
S: Stream<Item = Item> + Send + ?Sized,
|
||||
Self: Stream + Send + Sized,
|
||||
{
|
||||
fn ready_any<F>(self, f: F) -> Any<Self, Ready<bool>, impl FnMut(S::Item) -> Ready<bool>>
|
||||
where
|
||||
F: Fn(S::Item) -> bool;
|
||||
|
||||
fn ready_filter<'a, F>(self, f: F) -> Filter<Self, Ready<bool>, impl FnMut(&S::Item) -> Ready<bool> + 'a>
|
||||
where
|
||||
F: Fn(&S::Item) -> bool + 'a;
|
||||
|
||||
fn ready_filter_map<F, U>(self, f: F) -> FilterMap<Self, Ready<Option<U>>, impl FnMut(S::Item) -> Ready<Option<U>>>
|
||||
where
|
||||
F: Fn(S::Item) -> Option<U>;
|
||||
|
||||
fn ready_fold<T, F>(self, init: T, f: F) -> Fold<Self, Ready<T>, T, impl FnMut(T, S::Item) -> Ready<T>>
|
||||
where
|
||||
F: Fn(T, S::Item) -> T;
|
||||
|
||||
fn ready_for_each<F>(self, f: F) -> ForEach<Self, Ready<()>, impl FnMut(S::Item) -> Ready<()>>
|
||||
where
|
||||
F: FnMut(S::Item);
|
||||
|
||||
fn ready_take_while<'a, F>(self, f: F) -> TakeWhile<Self, Ready<bool>, impl FnMut(&S::Item) -> Ready<bool> + 'a>
|
||||
where
|
||||
F: Fn(&S::Item) -> bool + 'a;
|
||||
|
||||
fn ready_skip_while<'a, F>(self, f: F) -> SkipWhile<Self, Ready<bool>, impl FnMut(&S::Item) -> Ready<bool> + 'a>
|
||||
where
|
||||
F: Fn(&S::Item) -> bool + 'a;
|
||||
}
|
||||
|
||||
impl<Item, S> ReadyExt<Item, S> for S
|
||||
where
|
||||
S: Stream<Item = Item> + Send + ?Sized,
|
||||
Self: Stream + Send + Sized,
|
||||
{
|
||||
#[inline]
|
||||
fn ready_any<F>(self, f: F) -> Any<Self, Ready<bool>, impl FnMut(S::Item) -> Ready<bool>>
|
||||
where
|
||||
F: Fn(S::Item) -> bool,
|
||||
{
|
||||
self.any(move |t| ready(f(t)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn ready_filter<'a, F>(self, f: F) -> Filter<Self, Ready<bool>, impl FnMut(&S::Item) -> Ready<bool> + 'a>
|
||||
where
|
||||
F: Fn(&S::Item) -> bool + 'a,
|
||||
{
|
||||
self.filter(move |t| ready(f(t)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn ready_filter_map<F, U>(self, f: F) -> FilterMap<Self, Ready<Option<U>>, impl FnMut(S::Item) -> Ready<Option<U>>>
|
||||
where
|
||||
F: Fn(S::Item) -> Option<U>,
|
||||
{
|
||||
self.filter_map(move |t| ready(f(t)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn ready_fold<T, F>(self, init: T, f: F) -> Fold<Self, Ready<T>, T, impl FnMut(T, S::Item) -> Ready<T>>
|
||||
where
|
||||
F: Fn(T, S::Item) -> T,
|
||||
{
|
||||
self.fold(init, move |a, t| ready(f(a, t)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::unit_arg)]
|
||||
fn ready_for_each<F>(self, mut f: F) -> ForEach<Self, Ready<()>, impl FnMut(S::Item) -> Ready<()>>
|
||||
where
|
||||
F: FnMut(S::Item),
|
||||
{
|
||||
self.for_each(move |t| ready(f(t)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn ready_take_while<'a, F>(self, f: F) -> TakeWhile<Self, Ready<bool>, impl FnMut(&S::Item) -> Ready<bool> + 'a>
|
||||
where
|
||||
F: Fn(&S::Item) -> bool + 'a,
|
||||
{
|
||||
self.take_while(move |t| ready(f(t)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn ready_skip_while<'a, F>(self, f: F) -> SkipWhile<Self, Ready<bool>, impl FnMut(&S::Item) -> Ready<bool> + 'a>
|
||||
where
|
||||
F: Fn(&S::Item) -> bool + 'a,
|
||||
{
|
||||
self.skip_while(move |t| ready(f(t)))
|
||||
}
|
||||
}
|
35
src/core/utils/stream/try_ready.rs
Normal file
35
src/core/utils/stream/try_ready.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
//! Synchronous combinator extensions to futures::TryStream
|
||||
|
||||
use futures::{
|
||||
future::{ready, Ready},
|
||||
stream::{AndThen, TryStream, TryStreamExt},
|
||||
};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
/// Synchronous combinators to augment futures::TryStreamExt.
|
||||
///
|
||||
/// This interface is not necessarily complete; feel free to add as-needed.
|
||||
pub trait TryReadyExt<T, E, S>
|
||||
where
|
||||
S: TryStream<Ok = T, Error = E, Item = Result<T, E>> + Send + ?Sized,
|
||||
Self: TryStream + Send + Sized,
|
||||
{
|
||||
fn ready_and_then<U, F>(self, f: F) -> AndThen<Self, Ready<Result<U, E>>, impl FnMut(S::Ok) -> Ready<Result<U, E>>>
|
||||
where
|
||||
F: Fn(S::Ok) -> Result<U, E>;
|
||||
}
|
||||
|
||||
impl<T, E, S> TryReadyExt<T, E, S> for S
|
||||
where
|
||||
S: TryStream<Ok = T, Error = E, Item = Result<T, E>> + Send + ?Sized,
|
||||
Self: TryStream + Send + Sized,
|
||||
{
|
||||
#[inline]
|
||||
fn ready_and_then<U, F>(self, f: F) -> AndThen<Self, Ready<Result<U, E>>, impl FnMut(S::Ok) -> Ready<Result<U, E>>>
|
||||
where
|
||||
F: Fn(S::Ok) -> Result<U, E>,
|
||||
{
|
||||
self.and_then(move |t| ready(f(t)))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue