mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +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},
|
sync::{Arc, Mutex as StdMutex, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use lru_cache::LruCache;
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
use crate::{observability::FilterReloadHandles, Config, Result};
|
use crate::{observability::FilterReloadHandles, Config, Result};
|
||||||
|
|
||||||
pub(crate) mod account_data;
|
pub(crate) mod account_data;
|
||||||
|
|
@ -171,9 +168,7 @@ impl Services {
|
||||||
threads: rooms::threads::Service {
|
threads: rooms::threads::Service {
|
||||||
db,
|
db,
|
||||||
},
|
},
|
||||||
spaces: rooms::spaces::Service {
|
spaces: rooms::spaces::Service::new(200),
|
||||||
roomid_spacechunk_cache: Mutex::new(LruCache::new(200)),
|
|
||||||
},
|
|
||||||
user: db,
|
user: db,
|
||||||
},
|
},
|
||||||
transaction_ids: db,
|
transaction_ids: db,
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,19 @@ pub(crate) struct CachedSpaceChunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Service {
|
pub(crate) struct Service {
|
||||||
pub(crate) roomid_spacechunk_cache:
|
roomid_spacechunk_cache:
|
||||||
Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>,
|
Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
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)]
|
#[allow(clippy::too_many_lines)]
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub(crate) async fn get_hierarchy(
|
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> {
|
fn translate_joinrule(join_rule: &JoinRule) -> Result<SpaceRoomJoinRule> {
|
||||||
match join_rule {
|
match join_rule {
|
||||||
JoinRule::Invite => Ok(SpaceRoomJoinRule::Invite),
|
JoinRule::Invite => Ok(SpaceRoomJoinRule::Invite),
|
||||||
|
|
|
||||||
|
|
@ -103,10 +103,8 @@ impl Service {
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
.spaces
|
.spaces
|
||||||
.roomid_spacechunk_cache
|
.invalidate_cache(&pdu.room_id)
|
||||||
.lock()
|
.await;
|
||||||
.await
|
|
||||||
.remove(&pdu.room_id);
|
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -508,14 +508,12 @@ impl Service {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
TimelineEventType::SpaceChild => {
|
TimelineEventType::SpaceChild => {
|
||||||
if let Some(_state_key) = &pdu.state_key {
|
if pdu.state_key.is_some() {
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
.spaces
|
.spaces
|
||||||
.roomid_spacechunk_cache
|
.invalidate_cache(&pdu.room_id)
|
||||||
.lock()
|
.await;
|
||||||
.await
|
|
||||||
.remove(&pdu.room_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TimelineEventType::RoomMember => {
|
TimelineEventType::RoomMember => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue