move remaining runtime caches into their respective service
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
e1d1dac95e
commit
473b29d524
12 changed files with 108 additions and 85 deletions
|
@ -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,
|
||||
)),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue