mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
hide global services jank in service module
Mainly to make it easier to initialize the SERVICES global correctly in more than one place. Also this stuff really shouldn't live at the crate root anyway.
This commit is contained in:
parent
1fd20cdeba
commit
032e1ca3c6
3 changed files with 22 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
sync::{Arc, Mutex as StdMutex},
|
||||
sync::{Arc, Mutex as StdMutex, RwLock as StdRwLock},
|
||||
};
|
||||
|
||||
use lru_cache::LruCache;
|
||||
|
|
@ -22,6 +22,16 @@ pub(crate) mod transaction_ids;
|
|||
pub(crate) mod uiaa;
|
||||
pub(crate) mod users;
|
||||
|
||||
static SERVICES: StdRwLock<Option<&'static Services>> = StdRwLock::new(None);
|
||||
|
||||
/// Convenient access to the global [`Services`] instance
|
||||
pub(crate) fn services() -> &'static Services {
|
||||
SERVICES
|
||||
.read()
|
||||
.unwrap()
|
||||
.expect("SERVICES should be initialized when this is called")
|
||||
}
|
||||
|
||||
pub(crate) struct Services {
|
||||
pub(crate) appservice: appservice::Service,
|
||||
pub(crate) pusher: pusher::Service,
|
||||
|
|
@ -154,6 +164,11 @@ impl Services {
|
|||
})
|
||||
}
|
||||
|
||||
/// Installs `self` to be globally accessed via [`services`]
|
||||
pub(crate) fn install(self) {
|
||||
*SERVICES.write().unwrap() = Some(Box::leak(Box::new(self)));
|
||||
}
|
||||
|
||||
async fn memory_usage(&self) -> String {
|
||||
let lazy_load_waiting =
|
||||
self.rooms.lazy_loading.lazy_load_waiting.lock().await.len();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue