2024-05-09 15:59:08 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
use conduit::{implement, Result};
|
2024-10-07 17:54:27 +00:00
|
|
|
use database::{Deserialized, Json, Map};
|
2022-10-09 17:25:06 +02:00
|
|
|
use ruma::{CanonicalJsonObject, EventId};
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-06-28 22:51:39 +00:00
|
|
|
use crate::PduEvent;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
db: Data,
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
struct Data {
|
|
|
|
|
eventid_outlierpdu: Arc<Map>,
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:26:19 +00:00
|
|
|
impl crate::Service for Service {
|
|
|
|
|
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
|
|
|
|
Ok(Arc::new(Self {
|
2024-08-08 17:18:30 +00:00
|
|
|
db: Data {
|
|
|
|
|
eventid_outlierpdu: args.db["eventid_outlierpdu"].clone(),
|
|
|
|
|
},
|
2024-07-04 03:26:19 +00:00
|
|
|
}))
|
2024-05-27 03:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:26:19 +00:00
|
|
|
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
/// Returns the pdu from the outlier tree.
|
|
|
|
|
#[implement(Service)]
|
|
|
|
|
pub async fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<CanonicalJsonObject> {
|
|
|
|
|
self.db
|
|
|
|
|
.eventid_outlierpdu
|
2024-09-29 13:13:09 +00:00
|
|
|
.get(event_id)
|
2024-08-08 17:18:30 +00:00
|
|
|
.await
|
2024-09-28 15:14:48 +00:00
|
|
|
.deserialized()
|
2024-08-08 17:18:30 +00:00
|
|
|
}
|
2022-06-20 11:31:27 +02:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
/// Returns the pdu from the outlier tree.
|
|
|
|
|
#[implement(Service)]
|
|
|
|
|
pub async fn get_pdu_outlier(&self, event_id: &EventId) -> Result<PduEvent> {
|
|
|
|
|
self.db
|
|
|
|
|
.eventid_outlierpdu
|
2024-09-29 13:13:09 +00:00
|
|
|
.get(event_id)
|
2024-08-08 17:18:30 +00:00
|
|
|
.await
|
2024-09-28 15:14:48 +00:00
|
|
|
.deserialized()
|
2024-08-08 17:18:30 +00:00
|
|
|
}
|
2021-01-14 21:32:22 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
/// Append the PDU as an outlier.
|
|
|
|
|
#[implement(Service)]
|
|
|
|
|
#[tracing::instrument(skip(self, pdu), level = "debug")]
|
|
|
|
|
pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) {
|
2024-10-07 17:54:27 +00:00
|
|
|
self.db.eventid_outlierpdu.raw_put(event_id, Json(pdu));
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|