service, database: extract cache capacity to variable

This commit is contained in:
Lambda 2024-09-06 18:03:37 +00:00
parent b09c44a0ca
commit 29634f689a
2 changed files with 25 additions and 58 deletions

View file

@ -351,6 +351,15 @@ impl KeyValueDatabase {
}
};
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation,
reason = "saturating to usize is fine"
)]
let cache_capacity =
(100_000.0 * config.cache_capacity_modifier) as usize;
let db = Self {
db: builder.clone(),
userid_password: builder.open_tree("userid_password")?,
@ -482,46 +491,11 @@ impl KeyValueDatabase {
.try_into()
.expect("pdu cache capacity fits into usize"),
)),
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
auth_chain_cache: Mutex::new(LruCache::new(
(100_000.0 * config.cache_capacity_modifier) as usize,
)),
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
shorteventid_cache: Mutex::new(LruCache::new(
(100_000.0 * config.cache_capacity_modifier) as usize,
)),
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
eventidshort_cache: Mutex::new(LruCache::new(
(100_000.0 * config.cache_capacity_modifier) as usize,
)),
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
shortstatekey_cache: Mutex::new(LruCache::new(
(100_000.0 * config.cache_capacity_modifier) as usize,
)),
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
statekeyshort_cache: Mutex::new(LruCache::new(
(100_000.0 * config.cache_capacity_modifier) as usize,
)),
auth_chain_cache: Mutex::new(LruCache::new(cache_capacity)),
shorteventid_cache: Mutex::new(LruCache::new(cache_capacity)),
eventidshort_cache: Mutex::new(LruCache::new(cache_capacity)),
shortstatekey_cache: Mutex::new(LruCache::new(cache_capacity)),
statekeyshort_cache: Mutex::new(LruCache::new(cache_capacity)),
our_real_users_cache: RwLock::new(HashMap::new()),
appservice_in_room_cache: RwLock::new(HashMap::new()),
lasttimelinecount_cache: Mutex::new(HashMap::new()),

View file

@ -63,6 +63,14 @@ impl Services {
config: Config,
reload_handles: FilterReloadHandles,
) -> Result<Self> {
#[expect(
clippy::as_conversions,
clippy::cast_sign_loss,
clippy::cast_possible_truncation,
reason = "usize is an acceptable range to saturate to"
)]
let cache_capacity = (100.0 * config.cache_capacity_modifier) as usize;
Ok(Self {
appservice: appservice::Service::build(db)?,
pusher: pusher::Service {
@ -99,21 +107,11 @@ impl Services {
},
state_accessor: rooms::state_accessor::Service {
db,
#[expect(
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,
cache_capacity,
)),
#[expect(
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,
cache_capacity,
)),
},
state_cache: rooms::state_cache::Service {
@ -121,13 +119,8 @@ impl Services {
},
state_compressor: rooms::state_compressor::Service {
db,
#[expect(
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,
cache_capacity,
)),
},
timeline: rooms::timeline::Service {