Move shortstatehash queries from state_accessor to state service.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -31,26 +31,15 @@ use tuwunel_core::{
|
||||
Result, err,
|
||||
matrix::{Event, room_version, state_res::events::RoomCreateEvent},
|
||||
};
|
||||
use tuwunel_database::Map;
|
||||
|
||||
pub struct Service {
|
||||
services: Arc<crate::services::OnceServices>,
|
||||
db: Data,
|
||||
}
|
||||
|
||||
struct Data {
|
||||
shorteventid_shortstatehash: Arc<Map>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(Self {
|
||||
services: args.services.clone(),
|
||||
db: Data {
|
||||
shorteventid_shortstatehash: args.db["shorteventid_shortstatehash"].clone(),
|
||||
},
|
||||
}))
|
||||
Ok(Arc::new(Self { services: args.services.clone() }))
|
||||
}
|
||||
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
|
||||
@@ -18,7 +18,12 @@ pub async fn server_can_see_event(
|
||||
room_id: &RoomId,
|
||||
event_id: &EventId,
|
||||
) -> bool {
|
||||
let Ok(shortstatehash) = self.pdu_shortstatehash(event_id).await else {
|
||||
let Ok(shortstatehash) = self
|
||||
.services
|
||||
.state
|
||||
.pdu_shortstatehash(event_id)
|
||||
.await
|
||||
else {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ use tuwunel_core::{
|
||||
stream::{BroadbandExt, IterStream, ReadyExt, TryIgnore},
|
||||
},
|
||||
};
|
||||
use tuwunel_database::Deserialized;
|
||||
|
||||
use crate::rooms::{
|
||||
short::{ShortEventId, ShortStateHash, ShortStateKey},
|
||||
@@ -421,25 +420,3 @@ async fn load_full_state(&self, shortstatehash: ShortStateHash) -> Result<Arc<Co
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns the state hash at this event.
|
||||
#[implement(super::Service)]
|
||||
pub async fn pdu_shortstatehash(&self, event_id: &EventId) -> Result<ShortStateHash> {
|
||||
self.services
|
||||
.short
|
||||
.get_shorteventid(event_id)
|
||||
.and_then(|shorteventid| self.get_shortstatehash(shorteventid))
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns the state hash at this event.
|
||||
#[implement(super::Service)]
|
||||
pub async fn get_shortstatehash(&self, shorteventid: ShortEventId) -> Result<ShortStateHash> {
|
||||
const BUFSIZE: usize = size_of::<ShortEventId>();
|
||||
|
||||
self.db
|
||||
.shorteventid_shortstatehash
|
||||
.aqry::<BUFSIZE, _>(&shorteventid)
|
||||
.await
|
||||
.deserialized()
|
||||
}
|
||||
|
||||
@@ -83,7 +83,12 @@ pub async fn user_can_see_event(
|
||||
room_id: &RoomId,
|
||||
event_id: &EventId,
|
||||
) -> bool {
|
||||
let Ok(shortstatehash) = self.pdu_shortstatehash(event_id).await else {
|
||||
let Ok(shortstatehash) = self
|
||||
.services
|
||||
.state
|
||||
.pdu_shortstatehash(event_id)
|
||||
.await
|
||||
else {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user