improvement: auth chain cache
This commit is contained in:
parent
f5273f7eb1
commit
cfaa900e83
10 changed files with 201 additions and 176 deletions
|
@ -25,7 +25,7 @@ use std::{
|
|||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
mem,
|
||||
sync::{Arc, RwLock},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use super::{abstraction::Tree, admin::AdminCommand, pusher};
|
||||
|
@ -84,7 +84,8 @@ pub struct Rooms {
|
|||
/// RoomId + EventId -> Parent PDU EventId.
|
||||
pub(super) prevevent_parent: Arc<dyn Tree>,
|
||||
|
||||
pub(super) pdu_cache: RwLock<LruCache<EventId, Arc<PduEvent>>>,
|
||||
pub(super) pdu_cache: Mutex<LruCache<EventId, Arc<PduEvent>>>,
|
||||
pub(super) auth_chain_cache: Mutex<LruCache<EventId, HashSet<EventId>>>,
|
||||
}
|
||||
|
||||
impl Rooms {
|
||||
|
@ -109,7 +110,7 @@ impl Rooms {
|
|||
pub fn state_full(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
) -> Result<BTreeMap<(EventType, String), Arc<PduEvent>>> {
|
||||
) -> Result<HashMap<(EventType, String), Arc<PduEvent>>> {
|
||||
let state = self
|
||||
.stateid_shorteventid
|
||||
.scan_prefix(shortstatehash.to_be_bytes().to_vec())
|
||||
|
@ -282,7 +283,7 @@ impl Rooms {
|
|||
pub fn force_state(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
state: BTreeMap<(EventType, String), EventId>,
|
||||
state: HashMap<(EventType, String), EventId>,
|
||||
db: &Database,
|
||||
) -> Result<()> {
|
||||
let state_hash = self.calculate_hash(
|
||||
|
@ -402,11 +403,11 @@ impl Rooms {
|
|||
pub fn room_state_full(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<BTreeMap<(EventType, String), Arc<PduEvent>>> {
|
||||
) -> Result<HashMap<(EventType, String), Arc<PduEvent>>> {
|
||||
if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? {
|
||||
self.state_full(current_shortstatehash)
|
||||
} else {
|
||||
Ok(BTreeMap::new())
|
||||
Ok(HashMap::new())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -542,7 +543,7 @@ impl Rooms {
|
|||
///
|
||||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
pub fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> {
|
||||
if let Some(p) = self.pdu_cache.write().unwrap().get_mut(&event_id) {
|
||||
if let Some(p) = self.pdu_cache.lock().unwrap().get_mut(&event_id) {
|
||||
return Ok(Some(Arc::clone(p)));
|
||||
}
|
||||
|
||||
|
@ -568,7 +569,7 @@ impl Rooms {
|
|||
.transpose()?
|
||||
{
|
||||
self.pdu_cache
|
||||
.write()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(event_id.clone(), Arc::clone(&pdu));
|
||||
Ok(Some(pdu))
|
||||
|
@ -2520,4 +2521,10 @@ impl Rooms {
|
|||
|
||||
Ok(self.userroomid_leftstate.get(&userroom_id)?.is_some())
|
||||
}
|
||||
|
||||
pub fn auth_chain_cache(
|
||||
&self,
|
||||
) -> std::sync::MutexGuard<'_, LruCache<EventId, HashSet<EventId>>> {
|
||||
self.auth_chain_cache.lock().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue