simplify get_pdu() interface; eliminate unconditional Arc
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
58be22e695
commit
6175e72f1c
16 changed files with 51 additions and 52 deletions
|
@ -7,6 +7,7 @@ use std::{
|
|||
use conduit::{
|
||||
debug, debug_error, implement, info, pdu, trace, utils::math::continue_exponential_backoff_secs, warn, PduEvent,
|
||||
};
|
||||
use futures::TryFutureExt;
|
||||
use ruma::{api::federation::event::get_event, CanonicalJsonValue, EventId, RoomId, RoomVersionId, ServerName};
|
||||
|
||||
/// Find the event and auth it. Once the event is validated (steps 1 - 8)
|
||||
|
@ -42,7 +43,7 @@ pub(super) async fn fetch_and_handle_outliers<'a>(
|
|||
// a. Look in the main timeline (pduid_pdu tree)
|
||||
// b. Look at outlier pdu tree
|
||||
// (get_pdu_json checks both)
|
||||
if let Ok(local_pdu) = self.services.timeline.get_pdu(id).await {
|
||||
if let Ok(local_pdu) = self.services.timeline.get_pdu(id).map_ok(Arc::new).await {
|
||||
trace!("Found {id} in db");
|
||||
events_with_auth_events.push((id, Some(local_pdu), vec![]));
|
||||
continue;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use std::{
|
||||
collections::{hash_map, BTreeMap},
|
||||
sync::Arc,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use conduit::{debug, err, implement, warn, Error, Result};
|
||||
use futures::FutureExt;
|
||||
use futures::{FutureExt, TryFutureExt};
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind, events::StateEventType, CanonicalJsonValue, EventId, RoomId, ServerName, UserId,
|
||||
};
|
||||
|
@ -79,6 +80,7 @@ pub async fn handle_incoming_pdu<'a>(
|
|||
.services
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")
|
||||
.map_ok(Arc::new)
|
||||
.await?;
|
||||
|
||||
// Procure the room version
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
};
|
||||
|
||||
use conduit::{debug, debug_info, err, implement, trace, warn, Err, Error, PduEvent, Result};
|
||||
use futures::future::ready;
|
||||
use futures::{future::ready, TryFutureExt};
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind,
|
||||
events::StateEventType,
|
||||
|
@ -94,7 +94,7 @@ pub(super) async fn handle_outlier_pdu<'a>(
|
|||
// Build map of auth events
|
||||
let mut auth_events = HashMap::with_capacity(incoming_pdu.auth_events.len());
|
||||
for id in &incoming_pdu.auth_events {
|
||||
let Ok(auth_event) = self.services.timeline.get_pdu(id).await else {
|
||||
let Ok(auth_event) = self.services.timeline.get_pdu(id).map_ok(Arc::new).await else {
|
||||
warn!("Could not find auth event {id}");
|
||||
continue;
|
||||
};
|
||||
|
|
|
@ -17,7 +17,11 @@ use std::{
|
|||
time::Instant,
|
||||
};
|
||||
|
||||
use conduit::{utils::MutexMap, Err, PduEvent, Result, Server};
|
||||
use conduit::{
|
||||
utils::{MutexMap, TryFutureExtExt},
|
||||
Err, PduEvent, Result, Server,
|
||||
};
|
||||
use futures::TryFutureExt;
|
||||
use ruma::{
|
||||
events::room::create::RoomCreateEventContent, state_res::RoomVersion, EventId, OwnedEventId, OwnedRoomId, RoomId,
|
||||
RoomVersionId,
|
||||
|
@ -94,7 +98,12 @@ impl Service {
|
|||
async fn event_exists(&self, event_id: Arc<EventId>) -> bool { self.services.timeline.pdu_exists(&event_id).await }
|
||||
|
||||
async fn event_fetch(&self, event_id: Arc<EventId>) -> Option<Arc<PduEvent>> {
|
||||
self.services.timeline.get_pdu(&event_id).await.ok()
|
||||
self.services
|
||||
.timeline
|
||||
.get_pdu(&event_id)
|
||||
.map_ok(Arc::new)
|
||||
.ok()
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue