mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
add constructor for spaces service
Also adds a public function to invalidate the cache rather than exposing the entire cache publicly.
This commit is contained in:
parent
f702b6cccd
commit
f771d319b2
4 changed files with 19 additions and 16 deletions
|
|
@ -3,9 +3,6 @@ use std::{
|
|||
sync::{Arc, Mutex as StdMutex, OnceLock},
|
||||
};
|
||||
|
||||
use lru_cache::LruCache;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::{observability::FilterReloadHandles, Config, Result};
|
||||
|
||||
pub(crate) mod account_data;
|
||||
|
|
@ -171,9 +168,7 @@ impl Services {
|
|||
threads: rooms::threads::Service {
|
||||
db,
|
||||
},
|
||||
spaces: rooms::spaces::Service {
|
||||
roomid_spacechunk_cache: Mutex::new(LruCache::new(200)),
|
||||
},
|
||||
spaces: rooms::spaces::Service::new(200),
|
||||
user: db,
|
||||
},
|
||||
transaction_ids: db,
|
||||
|
|
|
|||
|
|
@ -45,11 +45,19 @@ pub(crate) struct CachedSpaceChunk {
|
|||
}
|
||||
|
||||
pub(crate) struct Service {
|
||||
pub(crate) roomid_spacechunk_cache:
|
||||
roomid_spacechunk_cache:
|
||||
Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
pub(crate) fn new(roomid_spacechunk_cache_size: usize) -> Self {
|
||||
Self {
|
||||
roomid_spacechunk_cache: Mutex::new(LruCache::new(
|
||||
roomid_spacechunk_cache_size,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn get_hierarchy(
|
||||
|
|
@ -518,6 +526,10 @@ impl Service {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn invalidate_cache(&self, room_id: &RoomId) {
|
||||
self.roomid_spacechunk_cache.lock().await.remove(room_id);
|
||||
}
|
||||
|
||||
fn translate_joinrule(join_rule: &JoinRule) -> Result<SpaceRoomJoinRule> {
|
||||
match join_rule {
|
||||
JoinRule::Invite => Ok(SpaceRoomJoinRule::Invite),
|
||||
|
|
|
|||
|
|
@ -103,10 +103,8 @@ impl Service {
|
|||
services()
|
||||
.rooms
|
||||
.spaces
|
||||
.roomid_spacechunk_cache
|
||||
.lock()
|
||||
.await
|
||||
.remove(&pdu.room_id);
|
||||
.invalidate_cache(&pdu.room_id)
|
||||
.await;
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,14 +508,12 @@ impl Service {
|
|||
};
|
||||
}
|
||||
TimelineEventType::SpaceChild => {
|
||||
if let Some(_state_key) = &pdu.state_key {
|
||||
if pdu.state_key.is_some() {
|
||||
services()
|
||||
.rooms
|
||||
.spaces
|
||||
.roomid_spacechunk_cache
|
||||
.lock()
|
||||
.await
|
||||
.remove(&pdu.room_id);
|
||||
.invalidate_cache(&pdu.room_id)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
TimelineEventType::RoomMember => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue