add constructor for state accessor service

This commit is contained in:
Charles Hall 2024-10-08 16:15:24 -07:00
parent a083ff9200
commit c6e2f8372c
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
2 changed files with 27 additions and 12 deletions

View file

@ -133,25 +133,25 @@ impl Services {
state: rooms::state::Service {
db,
},
state_accessor: rooms::state_accessor::Service {
state_accessor: rooms::state_accessor::Service::new(
db,
#[allow(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
server_visibility_cache: StdMutex::new(LruCache::new(
(100.0 * config.cache_capacity_modifier) as usize,
)),
{
(100.0 * config.cache_capacity_modifier) as usize
},
#[allow(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
user_visibility_cache: StdMutex::new(LruCache::new(
(100.0 * config.cache_capacity_modifier) as usize,
)),
},
{
(100.0 * config.cache_capacity_modifier) as usize
},
),
state_cache: rooms::state_cache::Service::new(db),
state_compressor: rooms::state_compressor::Service {
db,

View file

@ -38,14 +38,29 @@ mod data;
pub(crate) use data::Data;
pub(crate) struct Service {
pub(crate) db: &'static dyn Data,
pub(crate) server_visibility_cache:
db: &'static dyn Data,
server_visibility_cache:
Mutex<LruCache<(OwnedServerName, ShortStateHash), bool>>,
pub(crate) user_visibility_cache:
Mutex<LruCache<(OwnedUserId, ShortStateHash), bool>>,
user_visibility_cache: Mutex<LruCache<(OwnedUserId, ShortStateHash), bool>>,
}
impl Service {
pub(crate) fn new(
db: &'static dyn Data,
server_visibility_cache_size: usize,
user_visibility_cache_size: usize,
) -> Self {
Self {
db,
server_visibility_cache: Mutex::new(LruCache::new(
server_visibility_cache_size,
)),
user_visibility_cache: Mutex::new(LruCache::new(
user_visibility_cache_size,
)),
}
}
/// Builds a StateMap by iterating over all keys that start
/// with state_hash, this gives the full state for the given state_hash.
#[tracing::instrument(skip(self))]