add constructor for lazy-loading service

This commit is contained in:
Charles Hall 2024-10-08 16:10:30 -07:00
parent 3b28d0cfda
commit a083ff9200
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
2 changed files with 11 additions and 7 deletions

View file

@ -1,5 +1,5 @@
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::BTreeMap,
sync::{Arc, Mutex as StdMutex, OnceLock}, sync::{Arc, Mutex as StdMutex, OnceLock},
}; };
@ -88,10 +88,7 @@ impl Services {
typing: rooms::edus::typing::Service::new(), typing: rooms::edus::typing::Service::new(),
}, },
event_handler: rooms::event_handler::Service, event_handler: rooms::event_handler::Service,
lazy_loading: rooms::lazy_loading::Service { lazy_loading: rooms::lazy_loading::Service::new(db),
db,
lazy_load_waiting: Mutex::new(HashMap::new()),
},
metadata: db, metadata: db,
outlier: db, outlier: db,
pdu_metadata: rooms::pdu_metadata::Service { pdu_metadata: rooms::pdu_metadata::Service {

View file

@ -11,10 +11,10 @@ mod data;
pub(crate) use data::Data; pub(crate) use data::Data;
pub(crate) struct Service { pub(crate) struct Service {
pub(crate) db: &'static dyn Data, db: &'static dyn Data,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub(crate) lazy_load_waiting: Mutex< lazy_load_waiting: Mutex<
HashMap< HashMap<
(OwnedUserId, OwnedDeviceId, OwnedRoomId, PduCount), (OwnedUserId, OwnedDeviceId, OwnedRoomId, PduCount),
HashSet<OwnedUserId>, HashSet<OwnedUserId>,
@ -23,6 +23,13 @@ pub(crate) struct Service {
} }
impl Service { impl Service {
pub(crate) fn new(db: &'static dyn Data) -> Self {
Self {
db,
lazy_load_waiting: Mutex::new(HashMap::new()),
}
}
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub(crate) fn lazy_load_was_sent_before( pub(crate) fn lazy_load_was_sent_before(
&self, &self,