generalize return value wrapping to not require Arc

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-26 00:35:03 +00:00
parent 238523f177
commit f69c596f56
3 changed files with 18 additions and 7 deletions

View file

@ -1,10 +1,11 @@
use std::{fmt::Debug, mem::size_of_val, sync::Arc};
use std::{borrow::Borrow, fmt::Debug, mem::size_of_val, sync::Arc};
pub use conduit::pdu::{ShortEventId, ShortId, ShortRoomId};
use conduit::{err, implement, utils, utils::stream::ReadyExt, Result};
use database::{Deserialized, Map};
use futures::{Stream, StreamExt};
use ruma::{events::StateEventType, EventId, RoomId};
use serde::Deserialize;
use crate::{globals, Dep};
@ -136,7 +137,11 @@ pub async fn get_shortstatekey(&self, event_type: &StateEventType, state_key: &s
}
#[implement(Service)]
pub async fn get_eventid_from_short(&self, shorteventid: ShortEventId) -> Result<Arc<EventId>> {
pub async fn get_eventid_from_short<Id>(&self, shorteventid: ShortEventId) -> Result<Id>
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned,
<Id as ToOwned>::Owned: Borrow<EventId>,
{
const BUFSIZE: usize = size_of::<ShortEventId>();
self.db
@ -148,8 +153,10 @@ pub async fn get_eventid_from_short(&self, shorteventid: ShortEventId) -> Result
}
#[implement(Service)]
pub async fn multi_get_eventid_from_short<I>(&self, shorteventid: I) -> Vec<Result<Arc<EventId>>>
pub async fn multi_get_eventid_from_short<Id, I>(&self, shorteventid: I) -> Vec<Result<Id>>
where
Id: for<'de> Deserialize<'de> + Send + Sized + ToOwned,
<Id as ToOwned>::Owned: Borrow<EventId>,
I: Iterator<Item = ShortEventId> + Send,
{
const BUFSIZE: usize = size_of::<ShortEventId>();

View file

@ -102,7 +102,11 @@ impl Service {
.iter()
.stream()
.map(|&new| parse_compressed_state_event(new).1)
.then(|shorteventid| self.services.short.get_eventid_from_short(shorteventid))
.then(|shorteventid| {
self.services
.short
.get_eventid_from_short::<Box<_>>(shorteventid)
})
.ignore_err();
pin_mut!(event_ids);
@ -433,7 +437,7 @@ impl Service {
.await
.into_iter()
.stream()
.and_then(|event_id| async move { self.services.timeline.get_pdu(&event_id).await })
.and_then(|event_id: OwnedEventId| async move { self.services.timeline.get_pdu(&event_id).await })
.collect()
.await;

View file

@ -7,7 +7,7 @@ use conduit::{
};
use database::{Deserialized, Map};
use futures::{StreamExt, TryFutureExt};
use ruma::{events::StateEventType, EventId, RoomId};
use ruma::{events::StateEventType, EventId, OwnedEventId, RoomId};
use crate::{
rooms,
@ -74,7 +74,7 @@ impl Data {
.into_iter()
.stream()
.ready_filter_map(Result::ok)
.filter_map(|event_id| async move { self.services.timeline.get_pdu(&event_id).await.ok() })
.filter_map(|event_id: OwnedEventId| async move { self.services.timeline.get_pdu(&event_id).await.ok() })
.collect()
.await;