1mod append;
8mod backfill;
9mod build;
10mod checked;
11mod create;
12mod pdus;
13mod purge;
14mod redact;
15
16#[cfg(test)]
17mod tests;
18
19use std::{fmt::Write, sync::Arc};
20
21use async_trait::async_trait;
22use futures::{
23 FutureExt, StreamExt, TryFutureExt, TryStreamExt,
24 future::{Either, select, select_ok, try_join},
25 pin_mut,
26};
27use ruma::{
28 CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId,
29 UserId, api::Direction, events::room::encrypted::Relation, signatures::Verified,
30};
31use serde::Deserialize;
32use tuwunel_core::{
33 Err, Error, Result, at, err, implement,
34 utils::{
35 MutexMap, MutexMapGuard,
36 future::TryExtExt,
37 result::{LogErr, NotFound},
38 stream::{IterStream, TryReadyExt},
39 },
40 warn,
41};
42use tuwunel_database::{Database, Deserialized, Json, Map, Txn};
43pub use tuwunel_matrix::pdu::{PduId, RawPduId};
47use tuwunel_matrix::{
48 ShortEventId,
49 pdu::{PduCount, PduEvent},
50 room::state::resolution::FetchEvent,
51};
52
53pub use self::build::Collision;
54pub use self::pdus::{PdusIterItem, bias_count};
58pub(crate) use self::{
59 append::Incoming,
60 checked::{Mapped, Position},
61 redact::Restoration,
62};
63use crate::rooms::{
64 short::{ShortRoomId, ShortStateHash},
65 threads::RedactedRoot,
66};
67
68pub struct Service {
74 services: Arc<crate::services::OnceServices>,
75 db: Data,
76 pub mutex_insert: RoomMutexMap,
81}
82
83struct Data {
84 eventid_outlierpdu: Arc<Map>,
85 eventid_pduid: Arc<Map>,
86 pduid_pdu: Arc<Map>,
87 roomid_tscount_pducount: Arc<Map>,
88 db: Arc<Database>,
89}
90
91#[derive(Deserialize)]
95pub(crate) struct ExtractRelatesTo {
96 #[serde(rename = "m.relates_to")]
97 pub(crate) relates_to: Relation,
99}
100
101#[derive(Clone, Debug, Deserialize)]
102struct ExtractEventId {
103 event_id: OwnedEventId,
104}
105#[derive(Clone, Debug, Deserialize)]
106struct ExtractRelatesToEventId {
107 #[serde(rename = "m.relates_to")]
108 relates_to: ExtractEventId,
109}
110
111#[derive(Deserialize)]
112struct ExtractBody {
113 body: Option<String>,
114}
115
116type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
117pub type RoomMutexGuard = MutexMapGuard<OwnedRoomId, ()>;
122
123#[async_trait]
124impl crate::Service for Service {
125 fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
126 Ok(Arc::new(Self {
127 services: args.services.clone(),
128 db: Data {
129 eventid_outlierpdu: args.db["eventid_outlierpdu"].clone(),
130 eventid_pduid: args.db["eventid_pduid"].clone(),
131 pduid_pdu: args.db["pduid_pdu"].clone(),
132 roomid_tscount_pducount: args.db["roomid_tscount_pducount"].clone(),
133 db: args.db.clone(),
134 },
135 mutex_insert: RoomMutexMap::new(),
136 }))
137 }
138
139 async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
140 let mutex_insert = self.mutex_insert.len();
141 writeln!(out, "- insert_mutex: {mutex_insert}")?;
142
143 Ok(())
144 }
145
146 fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
147}
148
149#[implement(Service)]
154#[tracing::instrument(skip(self), level = "debug")]
155pub async fn replace_pdu(&self, pdu_id: &RawPduId, pdu_json: &CanonicalJsonObject) -> Result {
156 self.require_pdu(pdu_id).await?;
157
158 self.db.pduid_pdu.raw_put(pdu_id, Json(pdu_json));
159
160 Ok(())
161}
162
163#[implement(Service)]
168#[tracing::instrument(skip(self, pdu, root), level = "debug")]
169pub(super) async fn replace_redacted_pdu(
170 &self,
171 pdu_id: &RawPduId,
172 pdu: &CanonicalJsonObject,
173 root: Option<RedactedRoot>,
174) -> Result {
175 self.require_pdu(pdu_id).await?;
176 self.redaction_txn(pdu_id, pdu, root.as_ref())
177 .execute();
178
179 Ok(())
180}
181
182#[implement(Service)]
186fn redaction_txn(
187 &self,
188 pdu_id: &RawPduId,
189 pdu: &CanonicalJsonObject,
190 root: Option<&RedactedRoot>,
191) -> Txn {
192 let mut txn = self.db.db.txn();
193
194 if let Some(root) = root {
195 self.services
196 .threads
197 .stage_redacted_root(&mut txn, root);
198 }
199
200 self.stage_replace_pdu(&mut txn, pdu_id, pdu);
201 txn
202}
203
204#[implement(Service)]
205#[tracing::instrument(skip(self), level = "debug")]
206async fn require_pdu(&self, pdu_id: &RawPduId) -> Result {
207 if self.db.pduid_pdu.get(pdu_id).await.is_not_found() {
208 return Err!(Request(NotFound("PDU does not exist.")));
209 }
210
211 Ok(())
212}
213
214#[implement(Service)]
218pub(super) fn stage_replace_pdu(
219 &self,
220 txn: &mut Txn,
221 pdu_id: &RawPduId,
222 pdu_json: &CanonicalJsonObject,
223) {
224 txn.raw_put(&self.db.pduid_pdu, pdu_id, Json(pdu_json));
225}
226
227#[implement(Service)]
234#[tracing::instrument(skip(self, pdu), level = "debug")]
235pub async fn add_verified_outlier(
236 &self,
237 event_id: &EventId,
238 pdu: &CanonicalJsonObject,
239 verified: &Verified,
240) {
241 let kept = match verified {
242 | Verified::All =>
243 self.non_outlier_pdu_exists(event_id)
244 .is_ok()
245 .await,
246 | Verified::Signatures => self.pdu_exists(event_id).await,
247 };
248
249 if !kept {
250 self.add_pdu_outlier(event_id, pdu);
251 }
252}
253
254#[implement(Service)]
259#[tracing::instrument(skip(self, pdu), level = "debug")]
260pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) {
261 self.db
262 .eventid_outlierpdu
263 .raw_put(event_id, Json(pdu));
264}
265
266#[implement(Service)]
270#[tracing::instrument(skip(self), level = "debug")]
271pub async fn first_pdu_in_room(&self, room_id: &RoomId) -> Result<PduEvent> {
272 self.first_item_in_room(room_id).await.map(at!(1))
273}
274
275#[implement(Service)]
281#[tracing::instrument(skip(self), level = "debug")]
282pub async fn first_normal_pdu_in_room(&self, room_id: &RoomId) -> Result<PduEvent> {
283 self.first_item_after(room_id, Some(PduCount::Normal(0)))
284 .map_ok(at!(1))
285 .await
286}
287
288#[implement(Service)]
293#[tracing::instrument(skip(self), level = "debug")]
294#[inline]
295pub async fn latest_pdu_in_room(&self, room_id: &RoomId) -> Result<PduEvent> {
296 self.latest_item_in_room(None, room_id).await
297}
298
299#[implement(Service)]
304#[tracing::instrument(skip(self), level = "debug")]
305pub async fn first_item_in_room(&self, room_id: &RoomId) -> Result<(PduCount, PduEvent)> {
306 self.first_item_after(room_id, None).await
307}
308
309#[implement(Service)]
313async fn first_item_after(
314 &self,
315 room_id: &RoomId,
316 from: Option<PduCount>,
317) -> Result<(PduCount, PduEvent)> {
318 let pdus = self.pdus(None, room_id, from);
319
320 pin_mut!(pdus);
321 pdus.try_next()
322 .await?
323 .ok_or_else(|| err!(Request(NotFound("No PDU found in room"))))
324}
325
326#[implement(Service)]
331#[tracing::instrument(skip(self), level = "debug")]
332pub async fn latest_item_in_room(
333 &self,
334 sender_user: Option<&UserId>,
335 room_id: &RoomId,
336) -> Result<PduEvent> {
337 let pdus_rev = self.pdus_rev(sender_user, room_id, None);
338
339 pin_mut!(pdus_rev);
340 pdus_rev
341 .try_next()
342 .await?
343 .map(at!(1))
344 .ok_or_else(|| err!(Request(NotFound("No PDU's found in room"))))
345}
346
347#[implement(Service)]
352#[tracing::instrument(skip(self), level = "debug")]
353pub async fn prev_shortstatehash(
354 &self,
355 room_id: &RoomId,
356 before: PduCount,
357) -> Result<ShortStateHash> {
358 let shortroomid: ShortRoomId = self
359 .services
360 .short
361 .get_shortroomid(room_id)
362 .await
363 .map_err(|e| err!(Request(NotFound("Room {room_id:?} not found: {e:?}"))))?;
364
365 let before = PduId { shortroomid, count: before };
366
367 let prev = PduId {
368 shortroomid,
369 count: self.prev_timeline_count(&before).await?,
370 };
371
372 let shorteventid = self.get_shorteventid_from_pdu_id(&prev).await?;
373
374 self.services
375 .state
376 .get_shortstatehash(shorteventid)
377 .await
378}
379
380#[implement(Service)]
385#[tracing::instrument(skip(self), level = "debug")]
386pub async fn next_shortstatehash(
387 &self,
388 room_id: &RoomId,
389 after: PduCount,
390) -> Result<ShortStateHash> {
391 let shortroomid = self.shortroomid(room_id).await?;
392 let after = PduId { shortroomid, count: after };
393
394 let next = PduId {
395 shortroomid,
396 count: self.next_timeline_count(&after).await?,
397 };
398
399 let shorteventid = self.get_shorteventid_from_pdu_id(&next).await?;
400
401 self.services
402 .state
403 .get_shortstatehash(shorteventid)
404 .await
405}
406
407#[implement(Service)]
411async fn shortroomid(&self, room_id: &RoomId) -> Result<ShortRoomId> {
412 self.services
413 .short
414 .get_shortroomid(room_id)
415 .map_err(|e| err!(Request(NotFound("Room {room_id:?} not found: {e:?}"))))
416 .await
417}
418
419#[implement(Service)]
429#[tracing::instrument(skip(self), level = "debug")]
430pub async fn shortstatehash_after(
431 &self,
432 room_id: &RoomId,
433 count: PduCount,
434) -> Result<ShortStateHash> {
435 let shortroomid = self.shortroomid(room_id).await?;
436 let after = PduId { shortroomid, count };
437 let count = match self.next_timeline_count(&after).await {
438 | Ok(count) => count,
439 | Err(e) if !e.is_not_found() => return Err(e),
440 | Err(_) => {
441 return self
442 .services
443 .state
444 .get_room_shortstatehash(room_id)
445 .await;
446 },
447 };
448
449 let next = PduId { shortroomid, count };
450 let shorteventid = self.get_shorteventid_from_pdu_id(&next).await?;
451
452 self.services
453 .state
454 .get_shortstatehash(shorteventid)
455 .await
456}
457
458#[implement(Service)]
463#[tracing::instrument(skip(self), level = "debug")]
464pub async fn get_shortstatehash(
465 &self,
466 room_id: &RoomId,
467 count: PduCount,
468) -> Result<ShortStateHash> {
469 let shortroomid: ShortRoomId = self
470 .services
471 .short
472 .get_shortroomid(room_id)
473 .await
474 .map_err(|e| err!(Request(NotFound("Room {room_id:?} not found: {e:?}"))))?;
475
476 let pdu_id = PduId { shortroomid, count };
477
478 let shorteventid = self.get_shorteventid_from_pdu_id(&pdu_id).await?;
479
480 self.services
481 .state
482 .get_shortstatehash(shorteventid)
483 .await
484}
485
486#[implement(Service)]
491#[tracing::instrument(skip(self), level = "debug")]
492pub async fn prev_timeline_count(&self, before: &PduId) -> Result<PduCount> {
493 let before = Self::pdu_count_to_id(before.shortroomid, before.count, Direction::Backward);
494
495 let pdu_ids = self
496 .db
497 .pduid_pdu
498 .rev_keys_raw_from(&before)
499 .ready_try_take_while(|pdu_id: &RawPduId| Ok(pdu_id.is_room_eq(before)))
500 .ready_and_then(|pdu_id: RawPduId| Ok(pdu_id.pdu_count()));
501
502 pin_mut!(pdu_ids);
503 pdu_ids
504 .try_next()
505 .await
506 .log_err()?
507 .ok_or_else(|| err!(Request(NotFound("No earlier PDU's found in room"))))
508}
509
510#[implement(Service)]
515#[tracing::instrument(skip(self), level = "debug")]
516pub async fn next_timeline_count(&self, after: &PduId) -> Result<PduCount> {
517 let after = Self::pdu_count_to_id(after.shortroomid, after.count, Direction::Forward);
518
519 let pdu_ids = self
520 .db
521 .pduid_pdu
522 .keys_raw_from(&after)
523 .ready_try_take_while(|pdu_id: &RawPduId| Ok(pdu_id.is_room_eq(after)))
524 .ready_and_then(|pdu_id: RawPduId| Ok(pdu_id.pdu_count()));
525
526 pin_mut!(pdu_ids);
527 pdu_ids
528 .try_next()
529 .await
530 .log_err()?
531 .ok_or(err!(Request(NotFound("No more PDU's found in room"))))
532}
533
534#[implement(Service)]
540#[tracing::instrument(skip(self), level = "debug")]
541pub async fn last_timeline_count(
542 &self,
543 sender_user: Option<&UserId>,
544 room_id: &RoomId,
545 upper_bound: Option<PduCount>,
546) -> Result<PduCount> {
547 let upper_bound = upper_bound.unwrap_or_else(PduCount::max);
548 let pdus_rev = self.pdus_rev(sender_user, room_id, None);
549
550 pin_mut!(pdus_rev);
551 let last_count = pdus_rev
552 .ready_try_skip_while(|&(pducount, _)| Ok(pducount > upper_bound))
553 .try_next()
554 .await?
555 .map(at!(0))
556 .filter(|&count| matches!(count, PduCount::Normal(_)))
557 .unwrap_or_else(PduCount::max);
558
559 Ok(last_count)
560}
561
562#[implement(Service)]
568pub async fn get_event_id_near_ts(
569 &self,
570 room_id: &RoomId,
571 ts: MilliSecondsSinceUnixEpoch,
572 dir: Direction,
573) -> Result<(MilliSecondsSinceUnixEpoch, OwnedEventId)> {
574 self.get_pdu_id_near_ts(room_id, ts, dir)
575 .and_then(async |(ts, pdu_id)| {
576 self.get_event_id_from_pdu_id(&pdu_id)
577 .map_ok(|event_id| (ts, event_id))
578 .await
579 })
580 .await
581}
582
583#[implement(Service)]
589pub async fn get_pdu_id_near_ts(
590 &self,
591 room_id: &RoomId,
592 ts: MilliSecondsSinceUnixEpoch,
593 dir: Direction,
594) -> Result<(MilliSecondsSinceUnixEpoch, PduId)> {
595 let pdu_ids = self.pdu_ids_near_ts(room_id, ts, dir);
596
597 pin_mut!(pdu_ids);
598 pdu_ids
599 .try_next()
600 .await?
601 .ok_or_else(|| err!(Request(NotFound("No event found near this timestamp."))))
602}
603
604#[implement(Service)]
610pub async fn get_pdu_near_ts(
611 &self,
612 _user_id: Option<&UserId>,
613 room_id: &RoomId,
614 ts: MilliSecondsSinceUnixEpoch,
615 dir: Direction,
616) -> Result<PdusIterItem> {
617 let pdus = self
618 .pdu_ids_near_ts(room_id, ts, dir)
619 .map_ok(|(ts, pdu_id)| (ts, pdu_id.into()))
620 .and_then(async |(_, pdu_id): (_, RawPduId)| {
621 self.get_pdu_from_id(&pdu_id)
622 .map_ok(|pdu| (pdu_id.pdu_count(), pdu))
623 .await
624 });
625
626 pin_mut!(pdus);
627 pdus.try_next()
628 .await?
629 .ok_or_else(|| err!(Request(NotFound("No event found near this timestamp."))))
630}
631
632#[implement(Service)]
633async fn count_to_id(
634 &self,
635 room_id: &RoomId,
636 count: PduCount,
637 dir: Direction,
638) -> Result<RawPduId> {
639 let shortroomid: ShortRoomId = self
640 .services
641 .short
642 .get_shortroomid(room_id)
643 .await
644 .map_err(|e| err!(Request(NotFound("Room {room_id:?} not found: {e:?}"))))?;
645
646 Ok(Self::pdu_count_to_id(shortroomid, count, dir))
647}
648
649#[implement(Service)]
650fn pdu_count_to_id(shortroomid: ShortRoomId, count: PduCount, dir: Direction) -> RawPduId {
651 let count = match (count, dir) {
654 | (PduCount::Backfilled(0), Direction::Forward) => count,
655 | _ => count.saturating_inc(dir),
656 };
657
658 let pdu_id = PduId { shortroomid, count };
659
660 pdu_id.into()
661}
662
663#[implement(Service)]
668pub async fn get_pdu_from_shorteventid(&self, shorteventid: ShortEventId) -> Result<PduEvent> {
669 let event_id: OwnedEventId = self
670 .services
671 .short
672 .get_eventid_from_short(shorteventid)
673 .await?;
674
675 self.get_pdu(&event_id).await
676}
677
678#[implement(Service)]
683pub async fn get_pdu(&self, event_id: &EventId) -> Result<PduEvent> { self.get(event_id).await }
684
685#[implement(Service)]
690pub async fn get_outlier_pdu(&self, event_id: &EventId) -> Result<PduEvent> {
691 self.get_outlier(event_id).await
692}
693
694#[implement(Service)]
699pub async fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<PduEvent> {
700 self.get_non_outlier(event_id).await
701}
702
703#[implement(Service)]
707#[tracing::instrument(skip(self), level = "trace")]
708pub async fn get_pdu_at(&self, room_id: &RoomId, count: PduCount) -> Result<PduEvent> {
709 let shortroomid = self.shortroomid(room_id).await?;
710 let pdu_id: RawPduId = PduId { shortroomid, count }.into();
711
712 self.get_pdu_from_id(&pdu_id).await
713}
714
715#[implement(Service)]
720pub async fn get_pdu_from_id(&self, pdu_id: &RawPduId) -> Result<PduEvent> {
721 self.get_from_id(pdu_id).await
722}
723
724#[implement(Service)]
729pub async fn get_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> {
730 self.get(event_id).await
731}
732
733#[implement(Service)]
738pub async fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> {
739 self.get_outlier(event_id).await
740}
741
742#[implement(Service)]
747pub async fn get_non_outlier_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> {
748 self.get_non_outlier(event_id).await
749}
750
751#[implement(Service)]
756pub async fn get_pdu_json_from_id(&self, pdu_id: &RawPduId) -> Result<CanonicalJsonObject> {
757 self.get_from_id(pdu_id).await
758}
759
760#[implement(Service)]
766#[inline]
767pub async fn get<T>(&self, event_id: &EventId) -> Result<T>
768where
769 T: for<'de> Deserialize<'de>,
770{
771 let invert = |result: Result<T>| result.map_or_else(Ok, Err);
773 let accepted = self.get_non_outlier(event_id).map(invert);
774 let outlier = self.get_outlier(event_id).map(invert);
775
776 try_join(accepted, outlier)
777 .map(|result| match result {
778 | Err(value) => Ok(value),
779 | Ok((accepted, outlier)) if accepted.is_missing() => Err(outlier),
780 | Ok((accepted, _)) => Err(accepted),
781 })
782 .await
783}
784
785impl FetchEvent for &Service {
786 async fn get<T>(self, event_id: &EventId) -> Result<T>
787 where
788 T: for<'de> Deserialize<'de> + Send,
789 {
790 Service::get(self, event_id).await
791 }
792
793 async fn exists(self, event_id: &EventId) -> Result<bool> {
794 let non_outlier = self.non_outlier_pdu_exists(event_id);
795 let outlier = self.outlier_pdu_exists(event_id);
796 let classify = |first: Error, second: Result| match second {
797 | Ok(()) => Ok(true),
798 | Err(second) if first.is_not_found() && second.is_not_found() => Ok(false),
799 | Err(second) if first.is_not_found() => Err(second),
800 | Err(_) => Err(first),
801 };
802
803 pin_mut!(non_outlier, outlier);
804 match select(non_outlier, outlier).await {
805 | Either::Left((Ok(()), _)) | Either::Right((Ok(()), _)) => Ok(true),
806 | Either::Left((Err(first), second)) => classify(first, second.await),
807 | Either::Right((Err(first), second)) => classify(first, second.await),
808 }
809 }
810}
811
812#[implement(Service)]
817#[inline]
818pub async fn get_outlier<T>(&self, event_id: &EventId) -> Result<T>
819where
820 T: for<'de> Deserialize<'de>,
821{
822 self.db
823 .eventid_outlierpdu
824 .get(event_id)
825 .await
826 .deserialized()
827}
828
829#[implement(Service)]
834#[inline]
835pub async fn get_non_outlier<T>(&self, event_id: &EventId) -> Result<T>
836where
837 T: for<'de> Deserialize<'de>,
838{
839 let pdu_id = self.get_pdu_id(event_id).await?;
840
841 self.get_from_id(&pdu_id).await
842}
843
844#[implement(Service)]
849#[inline]
850pub async fn get_from_id<T>(&self, pdu_id: &RawPduId) -> Result<T>
851where
852 T: for<'de> Deserialize<'de>,
853{
854 self.db.pduid_pdu.get(pdu_id).await.deserialized()
855}
856
857#[implement(Service)]
862pub async fn pdu_exists<'a>(&'a self, event_id: &'a EventId) -> bool {
863 let non_outlier = self.non_outlier_pdu_exists(event_id);
864 let outlier = self.outlier_pdu_exists(event_id);
865
866 pin_mut!(non_outlier, outlier);
867 select_ok([non_outlier.left_future(), outlier.right_future()])
868 .await
869 .map(at!(0))
870 .is_ok()
871}
872
873#[implement(Service)]
880pub async fn non_outlier_pdus_exist<'a, I>(&self, event_ids: I) -> bool
881where
882 I: Iterator<Item = &'a EventId> + Send,
883{
884 event_ids
885 .stream()
886 .all(|event_id| self.non_outlier_pdu_exists(event_id).is_ok())
887 .await
888}
889
890#[implement(Service)]
897pub fn watch_event<'a>(&'a self, event_id: &EventId) -> impl Future<Output = ()> + Send + 'a {
898 self.db
899 .eventid_pduid
900 .watch_raw_prefix_once(event_id)
901}
902
903#[implement(Service)]
908pub async fn non_outlier_pdu_exists(&self, event_id: &EventId) -> Result {
909 let pduid = self.get_pdu_id(event_id).await?;
910
911 self.db.pduid_pdu.exists(&pduid).await
912}
913
914#[implement(Service)]
919#[inline]
920pub async fn outlier_pdu_exists(&self, event_id: &EventId) -> Result {
921 self.db.eventid_outlierpdu.exists(event_id).await
922}
923
924#[implement(Service)]
928pub async fn get_pdu_count(&self, event_id: &EventId) -> Result<PduCount> {
929 self.get_pdu_id(event_id)
930 .await
931 .map(RawPduId::pdu_count)
932}
933
934#[implement(Service)]
939pub async fn get_shorteventid_from_pdu_id(&self, pdu_id: &PduId) -> Result<ShortEventId> {
940 let event_id = self.get_event_id_from_pdu_id(pdu_id).await?;
941
942 self.services
943 .short
944 .get_shorteventid(&event_id)
945 .await
946}
947
948#[implement(Service)]
952pub async fn get_event_id_from_pdu_id(&self, pdu_id: &PduId) -> Result<OwnedEventId> {
953 let pdu_id: RawPduId = (*pdu_id).into();
954
955 self.get_pdu_from_id(&pdu_id)
956 .map_ok(|pdu| pdu.event_id)
957 .await
958}
959
960#[implement(Service)]
965pub async fn get_pdu_id_from_shorteventid(&self, shorteventid: ShortEventId) -> Result<RawPduId> {
966 let event_id: OwnedEventId = self
967 .services
968 .short
969 .get_eventid_from_short(shorteventid)
970 .await?;
971
972 self.get_pdu_id(&event_id).await
973}
974
975#[implement(Service)]
980pub async fn get_pdu_id(&self, event_id: &EventId) -> Result<RawPduId> {
981 self.db
982 .eventid_pduid
983 .get(event_id)
984 .await
985 .map(|handle| RawPduId::from(&*handle))
986}