mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
move our_real_users_cache to service
This commit is contained in:
parent
d3b62e598d
commit
9d62865b28
5 changed files with 56 additions and 47 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashSet, sync::Arc};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use ruma::{
|
||||
events::{AnyStrippedStateEvent, AnySyncStateEvent},
|
||||
|
|
@ -101,7 +101,10 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn update_joined_count(&self, room_id: &RoomId) -> Result<()> {
|
||||
fn update_joined_count(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<HashSet<OwnedUserId>> {
|
||||
let mut joinedcount = 0_u64;
|
||||
let mut invitedcount = 0_u64;
|
||||
let mut joined_servers = HashSet::new();
|
||||
|
|
@ -129,11 +132,6 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
|
|||
self.roomid_invitedcount
|
||||
.insert(room_id.as_bytes(), &invitedcount.to_be_bytes())?;
|
||||
|
||||
self.our_real_users_cache
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(room_id.to_owned(), Arc::new(real_users));
|
||||
|
||||
for old_joined_server in
|
||||
self.room_servers(room_id).filter_map(Result::ok)
|
||||
{
|
||||
|
|
@ -168,28 +166,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
|
|||
|
||||
self.appservice_in_room_cache.write().unwrap().remove(room_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn get_our_real_users(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Arc<HashSet<OwnedUserId>>> {
|
||||
let lookup = Lookup::OurRealUsers;
|
||||
|
||||
let maybe =
|
||||
self.our_real_users_cache.read().unwrap().get(room_id).cloned();
|
||||
if let Some(users) = maybe {
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
Ok(users)
|
||||
} else {
|
||||
self.update_joined_count(room_id)?;
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
Ok(Arc::clone(
|
||||
self.our_real_users_cache.read().unwrap().get(room_id).unwrap(),
|
||||
))
|
||||
}
|
||||
Ok(real_users)
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue