improvement: more auth chain caching
parent
ab7835dedb
commit
b813c34642
|
@ -87,7 +87,7 @@ pub struct Rooms {
|
||||||
pub(super) referencedevents: Arc<dyn Tree>,
|
pub(super) referencedevents: Arc<dyn Tree>,
|
||||||
|
|
||||||
pub(super) pdu_cache: Mutex<LruCache<EventId, Arc<PduEvent>>>,
|
pub(super) pdu_cache: Mutex<LruCache<EventId, Arc<PduEvent>>>,
|
||||||
pub(super) auth_chain_cache: Mutex<LruCache<EventId, HashSet<EventId>>>,
|
pub(super) auth_chain_cache: Mutex<LruCache<Vec<EventId>, HashSet<EventId>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rooms {
|
impl Rooms {
|
||||||
|
@ -2618,7 +2618,7 @@ impl Rooms {
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn auth_chain_cache(
|
pub fn auth_chain_cache(
|
||||||
&self,
|
&self,
|
||||||
) -> std::sync::MutexGuard<'_, LruCache<EventId, HashSet<EventId>>> {
|
) -> std::sync::MutexGuard<'_, LruCache<Vec<EventId>, HashSet<EventId>>> {
|
||||||
self.auth_chain_cache.lock().unwrap()
|
self.auth_chain_cache.lock().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1727,9 +1727,13 @@ fn get_auth_chain(starting_events: Vec<EventId>, db: &Database) -> Result<HashSe
|
||||||
let mut full_auth_chain = HashSet::new();
|
let mut full_auth_chain = HashSet::new();
|
||||||
|
|
||||||
let mut cache = db.rooms.auth_chain_cache();
|
let mut cache = db.rooms.auth_chain_cache();
|
||||||
for event_id in starting_events {
|
if let Some(cached) = cache.get_mut(&starting_events) {
|
||||||
let auth_chain = if let Some(cached) = cache.get_mut(&event_id) {
|
return Ok(cached.clone());
|
||||||
cached.clone()
|
}
|
||||||
|
|
||||||
|
for event_id in &starting_events {
|
||||||
|
if let Some(cached) = cache.get_mut(&[event_id.clone()][..]) {
|
||||||
|
full_auth_chain.extend(cached.iter().cloned());
|
||||||
} else {
|
} else {
|
||||||
drop(cache);
|
drop(cache);
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
@ -1741,14 +1745,15 @@ fn get_auth_chain(starting_events: Vec<EventId>, db: &Database) -> Result<HashSe
|
||||||
|
|
||||||
cache = db.rooms.auth_chain_cache();
|
cache = db.rooms.auth_chain_cache();
|
||||||
|
|
||||||
cache.insert(event_id, auth_chain.clone());
|
cache.insert(vec![event_id.clone()], auth_chain.clone());
|
||||||
|
|
||||||
auth_chain
|
full_auth_chain.extend(auth_chain);
|
||||||
};
|
};
|
||||||
|
|
||||||
full_auth_chain.extend(auth_chain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache.insert(starting_events, full_auth_chain.clone());
|
||||||
|
|
||||||
Ok(full_auth_chain)
|
Ok(full_auth_chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue