parallel query for outlier/non-outlier pdu data

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-27 05:57:20 +00:00
parent dd8c646b63
commit 2aeee4f509

View file

@ -12,7 +12,7 @@ use conduit::{
Err, PduCount, PduEvent, Result, Err, PduCount, PduEvent, Result,
}; };
use database::{Database, Deserialized, Json, KeyVal, Map}; use database::{Database, Deserialized, Json, KeyVal, Map};
use futures::{Stream, StreamExt}; use futures::{future::select_ok, FutureExt, Stream, StreamExt};
use ruma::{api::Direction, CanonicalJsonObject, EventId, OwnedRoomId, OwnedUserId, RoomId, UserId}; use ruma::{api::Direction, CanonicalJsonObject, EventId, OwnedRoomId, OwnedUserId, RoomId, UserId};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -82,11 +82,14 @@ impl Data {
/// Returns the json of a pdu. /// Returns the json of a pdu.
pub(super) async fn get_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> { pub(super) async fn get_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> {
if let Ok(pdu) = self.get_non_outlier_pdu_json(event_id).await { let accepted = self.get_non_outlier_pdu_json(event_id).boxed();
return Ok(pdu); let outlier = self
} .eventid_outlierpdu
.get(event_id)
.map(Deserialized::deserialized)
.boxed();
self.eventid_outlierpdu.get(event_id).await.deserialized() select_ok([accepted, outlier]).await.map(at!(0))
} }
/// Returns the json of a pdu. /// Returns the json of a pdu.
@ -131,11 +134,14 @@ impl Data {
/// ///
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline. /// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
pub(super) async fn get_pdu_owned(&self, event_id: &EventId) -> Result<PduEvent> { pub(super) async fn get_pdu_owned(&self, event_id: &EventId) -> Result<PduEvent> {
if let Ok(pdu) = self.get_non_outlier_pdu(event_id).await { let accepted = self.get_non_outlier_pdu(event_id).boxed();
return Ok(pdu); let outlier = self
} .eventid_outlierpdu
.get(event_id)
.map(Deserialized::deserialized)
.boxed();
self.eventid_outlierpdu.get(event_id).await.deserialized() select_ok([accepted, outlier]).await.map(at!(0))
} }
/// Like get_non_outlier_pdu(), but without the expense of fetching and /// Like get_non_outlier_pdu(), but without the expense of fetching and