move remaining runtime caches into their respective service

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-02 22:40:58 +00:00
parent e1d1dac95e
commit 473b29d524
12 changed files with 108 additions and 85 deletions

View file

@ -38,7 +38,6 @@ zstd_compression = [
chrono.workspace = true
conduit-core.workspace = true
log.workspace = true
lru-cache.workspace = true
ruma.workspace = true
rust-rocksdb.workspace = true
tokio.workspace = true

View file

@ -1,41 +1,21 @@
use std::{
collections::{BTreeMap, HashMap},
ops::Index,
sync::{Arc, Mutex, RwLock},
};
use std::{ops::Index, sync::Arc};
use conduit::{PduCount, Result, Server};
use lru_cache::LruCache;
use ruma::{CanonicalJsonValue, OwnedDeviceId, OwnedRoomId, OwnedUserId};
use conduit::{Result, Server};
use crate::{cork::Cork, maps, maps::Maps, Engine, Map};
pub struct Database {
pub db: Arc<Engine>,
pub map: Maps,
//TODO: not a database
pub userdevicesessionid_uiaarequest: RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>,
pub auth_chain_cache: Mutex<LruCache<Vec<u64>, Arc<[u64]>>>,
pub appservice_in_room_cache: RwLock<HashMap<OwnedRoomId, HashMap<String, bool>>>,
pub lasttimelinecount_cache: Mutex<HashMap<OwnedRoomId, PduCount>>,
}
impl Database {
/// Load an existing database or create a new one.
pub async fn open(server: &Arc<Server>) -> Result<Self> {
let config = &server.config;
let db = Engine::open(server)?;
Ok(Self {
db: db.clone(),
map: maps::open(&db)?,
userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()),
appservice_in_room_cache: RwLock::new(HashMap::new()),
lasttimelinecount_cache: Mutex::new(HashMap::new()),
auth_chain_cache: Mutex::new(LruCache::new(
(f64::from(config.auth_chain_cache_capacity) * config.conduit_cache_capacity_modifier) as usize,
)),
})
}