Unbox and pin various either-or futures.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#![type_length_limit = "16384"] //TODO: reduce me
|
||||
#![type_length_limit = "65536"] //TODO: reduce me
|
||||
#![allow(clippy::toplevel_ref_arg)]
|
||||
|
||||
pub mod client;
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
use std::{borrow::Borrow, sync::Arc};
|
||||
|
||||
use futures::{FutureExt, Stream, TryFutureExt, TryStreamExt, future::select_ok, pin_mut};
|
||||
use futures::{
|
||||
Stream, TryFutureExt, TryStreamExt,
|
||||
future::{
|
||||
Either::{Left, Right},
|
||||
select_ok,
|
||||
},
|
||||
pin_mut,
|
||||
};
|
||||
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, api::Direction};
|
||||
use tuwunel_core::{
|
||||
Err, PduCount, PduEvent, Result, at, err,
|
||||
@@ -81,6 +88,7 @@ impl Data {
|
||||
}
|
||||
|
||||
/// Returns the `count` of this pdu's id.
|
||||
#[inline]
|
||||
pub(super) async fn get_pdu_count(&self, event_id: &EventId) -> Result<PduCount> {
|
||||
self.get_pdu_id(event_id)
|
||||
.await
|
||||
@@ -88,6 +96,7 @@ impl Data {
|
||||
}
|
||||
|
||||
/// Returns the json of a pdu.
|
||||
#[inline]
|
||||
pub(super) async fn get_outlier_pdu_json(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
@@ -99,14 +108,19 @@ impl Data {
|
||||
}
|
||||
|
||||
/// Returns the json of a pdu.
|
||||
#[inline]
|
||||
pub(super) async fn get_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> {
|
||||
let accepted = self.get_non_outlier_pdu_json(event_id).boxed();
|
||||
let outlier = self.get_outlier_pdu_json(event_id).boxed();
|
||||
let accepted = self.get_non_outlier_pdu_json(event_id);
|
||||
let outlier = self.get_outlier_pdu_json(event_id);
|
||||
|
||||
select_ok([accepted, outlier]).await.map(at!(0))
|
||||
pin_mut!(accepted, outlier);
|
||||
select_ok([Left(accepted), Right(outlier)])
|
||||
.await
|
||||
.map(at!(0))
|
||||
}
|
||||
|
||||
/// Returns the json of a pdu.
|
||||
#[inline]
|
||||
pub(super) async fn get_non_outlier_pdu_json(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
@@ -126,6 +140,7 @@ impl Data {
|
||||
}
|
||||
|
||||
/// Returns the pdu directly from `eventid_pduid` only.
|
||||
#[inline]
|
||||
pub(super) async fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<PduEvent> {
|
||||
let pduid = self.get_pdu_id(event_id).await?;
|
||||
|
||||
@@ -134,6 +149,7 @@ impl Data {
|
||||
|
||||
/// Like get_non_outlier_pdu(), but without the expense of fetching and
|
||||
/// parsing the PduEvent
|
||||
#[inline]
|
||||
pub(super) async fn non_outlier_pdu_exists(&self, event_id: &EventId) -> Result {
|
||||
let pduid = self.get_pdu_id(event_id).await?;
|
||||
|
||||
@@ -143,6 +159,7 @@ impl Data {
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[inline]
|
||||
pub(super) async fn get_outlier_pdu(&self, event_id: &EventId) -> Result<PduEvent> {
|
||||
self.eventid_outlierpdu
|
||||
.get(event_id)
|
||||
@@ -153,11 +170,15 @@ impl Data {
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[inline]
|
||||
pub(super) async fn get_pdu(&self, event_id: &EventId) -> Result<PduEvent> {
|
||||
let accepted = self.get_non_outlier_pdu(event_id).boxed();
|
||||
let outlier = self.get_outlier_pdu(event_id).boxed();
|
||||
let accepted = self.get_non_outlier_pdu(event_id);
|
||||
let outlier = self.get_outlier_pdu(event_id);
|
||||
|
||||
select_ok([accepted, outlier]).await.map(at!(0))
|
||||
pin_mut!(accepted, outlier);
|
||||
select_ok([Left(accepted), Right(outlier)])
|
||||
.await
|
||||
.map(at!(0))
|
||||
}
|
||||
|
||||
/// Like get_non_outlier_pdu(), but without the expense of fetching and
|
||||
@@ -168,11 +189,13 @@ impl Data {
|
||||
}
|
||||
|
||||
/// Like get_pdu(), but without the expense of fetching and parsing the data
|
||||
#[inline]
|
||||
pub(super) async fn pdu_exists(&self, event_id: &EventId) -> Result {
|
||||
let non_outlier = self.non_outlier_pdu_exists(event_id).boxed();
|
||||
let outlier = self.outlier_pdu_exists(event_id).boxed();
|
||||
let non_outlier = self.non_outlier_pdu_exists(event_id);
|
||||
let outlier = self.outlier_pdu_exists(event_id);
|
||||
|
||||
select_ok([non_outlier, outlier])
|
||||
pin_mut!(non_outlier, outlier);
|
||||
select_ok([Left(non_outlier), Right(outlier)])
|
||||
.await
|
||||
.map(at!(0))
|
||||
}
|
||||
@@ -180,11 +203,13 @@ impl Data {
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// This does __NOT__ check the outliers `Tree`.
|
||||
#[inline]
|
||||
pub(super) async fn get_pdu_from_id(&self, pdu_id: &RawPduId) -> Result<PduEvent> {
|
||||
self.pduid_pdu.get(pdu_id).await.deserialized()
|
||||
}
|
||||
|
||||
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
|
||||
#[inline]
|
||||
pub(super) async fn get_pdu_json_from_id(
|
||||
&self,
|
||||
pdu_id: &RawPduId,
|
||||
@@ -237,6 +262,7 @@ impl Data {
|
||||
/// Returns an iterator over all events and their tokens in a room that
|
||||
/// happened before the event with id `until` in reverse-chronological
|
||||
/// order.
|
||||
#[inline]
|
||||
pub(super) fn pdus_rev<'a>(
|
||||
&'a self,
|
||||
user_id: Option<&'a UserId>,
|
||||
@@ -254,6 +280,7 @@ impl Data {
|
||||
.try_flatten_stream()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super) fn pdus<'a>(
|
||||
&'a self,
|
||||
user_id: Option<&'a UserId>,
|
||||
|
||||
@@ -173,7 +173,6 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Returns the json of a pdu.
|
||||
#[inline]
|
||||
pub async fn get_non_outlier_pdu_json(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
@@ -182,7 +181,6 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Returns the pdu's id.
|
||||
#[inline]
|
||||
pub async fn get_pdu_id(&self, event_id: &EventId) -> Result<RawPduId> {
|
||||
self.db.get_pdu_id(event_id).await
|
||||
}
|
||||
@@ -190,7 +188,6 @@ impl Service {
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[inline]
|
||||
pub async fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<impl Event> {
|
||||
self.db.get_non_outlier_pdu(event_id).await
|
||||
}
|
||||
@@ -198,7 +195,6 @@ impl Service {
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[inline]
|
||||
pub async fn get_pdu(&self, event_id: &EventId) -> Result<PduEvent> {
|
||||
self.db.get_pdu(event_id).await
|
||||
}
|
||||
@@ -206,13 +202,11 @@ impl Service {
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// This does __NOT__ check the outliers `Tree`.
|
||||
#[inline]
|
||||
pub async fn get_pdu_from_id(&self, pdu_id: &RawPduId) -> Result<PduEvent> {
|
||||
self.db.get_pdu_from_id(pdu_id).await
|
||||
}
|
||||
|
||||
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
|
||||
#[inline]
|
||||
pub async fn get_pdu_json_from_id(&self, pdu_id: &RawPduId) -> Result<CanonicalJsonObject> {
|
||||
self.db.get_pdu_json_from_id(pdu_id).await
|
||||
}
|
||||
@@ -220,7 +214,6 @@ impl Service {
|
||||
/// Checks if pdu exists
|
||||
///
|
||||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[inline]
|
||||
pub fn pdu_exists<'a>(
|
||||
&'a self,
|
||||
event_id: &'a EventId,
|
||||
@@ -236,7 +229,6 @@ impl Service {
|
||||
|
||||
/// Returns an iterator over all PDUs in a room. Unknown rooms produce no
|
||||
/// items.
|
||||
#[inline]
|
||||
pub fn all_pdus<'a>(
|
||||
&'a self,
|
||||
user_id: &'a UserId,
|
||||
|
||||
Reference in New Issue
Block a user