From f702b6cccdc18f26486180c4f6fded6257d8b351 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Tue, 8 Oct 2024 16:16:54 -0700 Subject: [PATCH] add constructor for state compressor service --- src/service.rs | 10 +++++----- src/service/rooms/state_compressor.rs | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/service.rs b/src/service.rs index b5f356aa..07a48520 100644 --- a/src/service.rs +++ b/src/service.rs @@ -153,17 +153,17 @@ impl Services { }, ), state_cache: rooms::state_cache::Service::new(db), - state_compressor: rooms::state_compressor::Service { + state_compressor: rooms::state_compressor::Service::new( db, #[allow( clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation )] - stateinfo_cache: StdMutex::new(LruCache::new( - (100.0 * config.cache_capacity_modifier) as usize, - )), - }, + { + (100.0 * config.cache_capacity_modifier) as usize + }, + ), timeline: rooms::timeline::Service::new( db, config.pdu_cache_capacity, diff --git a/src/service/rooms/state_compressor.rs b/src/service/rooms/state_compressor.rs index 4232a325..cac73fe0 100644 --- a/src/service/rooms/state_compressor.rs +++ b/src/service/rooms/state_compressor.rs @@ -72,6 +72,16 @@ impl CompressedStateEvent { } impl Service { + pub(crate) fn new( + db: &'static dyn Data, + stateinfo_cache_size: usize, + ) -> Self { + Self { + db, + stateinfo_cache: Mutex::new(LruCache::new(stateinfo_cache_size)), + } + } + /// Returns a stack with info on shortstatehash, full state, added diff and /// removed diff for the selected shortstatehash and each parent layer. #[allow(clippy::type_complexity)]