mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
service, database: extract cache capacity to variable
This commit is contained in:
parent
b09c44a0ca
commit
29634f689a
2 changed files with 25 additions and 58 deletions
|
|
@ -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 {
|
let db = Self {
|
||||||
db: builder.clone(),
|
db: builder.clone(),
|
||||||
userid_password: builder.open_tree("userid_password")?,
|
userid_password: builder.open_tree("userid_password")?,
|
||||||
|
|
@ -482,46 +491,11 @@ impl KeyValueDatabase {
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("pdu cache capacity fits into usize"),
|
.expect("pdu cache capacity fits into usize"),
|
||||||
)),
|
)),
|
||||||
#[expect(
|
auth_chain_cache: Mutex::new(LruCache::new(cache_capacity)),
|
||||||
clippy::as_conversions,
|
shorteventid_cache: Mutex::new(LruCache::new(cache_capacity)),
|
||||||
clippy::cast_sign_loss,
|
eventidshort_cache: Mutex::new(LruCache::new(cache_capacity)),
|
||||||
clippy::cast_possible_truncation
|
shortstatekey_cache: Mutex::new(LruCache::new(cache_capacity)),
|
||||||
)]
|
statekeyshort_cache: Mutex::new(LruCache::new(cache_capacity)),
|
||||||
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,
|
|
||||||
)),
|
|
||||||
our_real_users_cache: RwLock::new(HashMap::new()),
|
our_real_users_cache: RwLock::new(HashMap::new()),
|
||||||
appservice_in_room_cache: RwLock::new(HashMap::new()),
|
appservice_in_room_cache: RwLock::new(HashMap::new()),
|
||||||
lasttimelinecount_cache: Mutex::new(HashMap::new()),
|
lasttimelinecount_cache: Mutex::new(HashMap::new()),
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,14 @@ impl Services {
|
||||||
config: Config,
|
config: Config,
|
||||||
reload_handles: FilterReloadHandles,
|
reload_handles: FilterReloadHandles,
|
||||||
) -> Result<Self> {
|
) -> 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 {
|
Ok(Self {
|
||||||
appservice: appservice::Service::build(db)?,
|
appservice: appservice::Service::build(db)?,
|
||||||
pusher: pusher::Service {
|
pusher: pusher::Service {
|
||||||
|
|
@ -99,21 +107,11 @@ impl Services {
|
||||||
},
|
},
|
||||||
state_accessor: rooms::state_accessor::Service {
|
state_accessor: rooms::state_accessor::Service {
|
||||||
db,
|
db,
|
||||||
#[expect(
|
|
||||||
clippy::as_conversions,
|
|
||||||
clippy::cast_sign_loss,
|
|
||||||
clippy::cast_possible_truncation
|
|
||||||
)]
|
|
||||||
server_visibility_cache: StdMutex::new(LruCache::new(
|
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(
|
user_visibility_cache: StdMutex::new(LruCache::new(
|
||||||
(100.0 * config.cache_capacity_modifier) as usize,
|
cache_capacity,
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
state_cache: rooms::state_cache::Service {
|
state_cache: rooms::state_cache::Service {
|
||||||
|
|
@ -121,13 +119,8 @@ impl Services {
|
||||||
},
|
},
|
||||||
state_compressor: rooms::state_compressor::Service {
|
state_compressor: rooms::state_compressor::Service {
|
||||||
db,
|
db,
|
||||||
#[expect(
|
|
||||||
clippy::as_conversions,
|
|
||||||
clippy::cast_sign_loss,
|
|
||||||
clippy::cast_possible_truncation
|
|
||||||
)]
|
|
||||||
stateinfo_cache: StdMutex::new(LruCache::new(
|
stateinfo_cache: StdMutex::new(LruCache::new(
|
||||||
(100.0 * config.cache_capacity_modifier) as usize,
|
cache_capacity,
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
timeline: rooms::timeline::Service {
|
timeline: rooms::timeline::Service {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue