mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 00:01:24 +01:00
move appservice_in_room_cache to service
This commit is contained in:
parent
9d62865b28
commit
107f4521e0
3 changed files with 39 additions and 40 deletions
|
|
@ -27,6 +27,8 @@ pub(crate) use data::Data;
|
|||
|
||||
pub(crate) struct Service {
|
||||
db: &'static dyn Data,
|
||||
appservice_in_room_cache:
|
||||
RwLock<HashMap<OwnedRoomId, HashMap<String, bool>>>,
|
||||
our_real_users_cache:
|
||||
RwLock<HashMap<OwnedRoomId, Arc<HashSet<OwnedUserId>>>>,
|
||||
}
|
||||
|
|
@ -38,6 +40,7 @@ impl Service {
|
|||
Self {
|
||||
db,
|
||||
our_real_users_cache: RwLock::new(HashMap::new()),
|
||||
appservice_in_room_cache: RwLock::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -309,6 +312,7 @@ impl Service {
|
|||
.write()
|
||||
.unwrap()
|
||||
.insert(room_id.to_owned(), our_real_users.clone());
|
||||
self.appservice_in_room_cache.write().unwrap().remove(room_id);
|
||||
|
||||
Ok(our_real_users)
|
||||
}
|
||||
|
|
@ -340,7 +344,31 @@ impl Service {
|
|||
room_id: &RoomId,
|
||||
appservice: &RegistrationInfo,
|
||||
) -> Result<bool> {
|
||||
self.db.appservice_in_room(room_id, appservice)
|
||||
let lookup = Lookup::AppserviceInRoom;
|
||||
|
||||
if let Some(in_room) = self
|
||||
.appservice_in_room_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(room_id)
|
||||
.and_then(|map| map.get(&appservice.registration.id))
|
||||
.copied()
|
||||
{
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
return Ok(in_room);
|
||||
}
|
||||
|
||||
let in_room = self.db.appservice_in_room(room_id, appservice)?;
|
||||
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
self.appservice_in_room_cache
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.to_owned())
|
||||
.or_default()
|
||||
.insert(appservice.registration.id.clone(), in_room);
|
||||
|
||||
Ok(in_room)
|
||||
}
|
||||
|
||||
/// Makes a user forget a room.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue