mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
move shortstatekey_cache to service
This commit is contained in:
parent
190b788683
commit
d3b62e598d
4 changed files with 35 additions and 35 deletions
|
|
@ -41,6 +41,8 @@ pub(crate) struct Service {
|
|||
eventidshort_cache: Mutex<LruCache<OwnedEventId, ShortEventId>>,
|
||||
statekeyshort_cache:
|
||||
Mutex<LruCache<(StateEventType, String), ShortStateKey>>,
|
||||
shortstatekey_cache:
|
||||
Mutex<LruCache<ShortStateKey, (StateEventType, String)>>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
|
|
@ -49,6 +51,7 @@ impl Service {
|
|||
shorteventid_cache_size: usize,
|
||||
eventidshort_cache_size: usize,
|
||||
statekeyshort_cache_size: usize,
|
||||
shortstatekey_cache_size: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
db,
|
||||
|
|
@ -61,6 +64,9 @@ impl Service {
|
|||
statekeyshort_cache: Mutex::new(LruCache::new(
|
||||
statekeyshort_cache_size,
|
||||
)),
|
||||
shortstatekey_cache: Mutex::new(LruCache::new(
|
||||
shortstatekey_cache_size,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +195,25 @@ impl Service {
|
|||
&self,
|
||||
shortstatekey: ShortStateKey,
|
||||
) -> Result<(StateEventType, String)> {
|
||||
self.db.get_statekey_from_short(shortstatekey)
|
||||
let lookup = Lookup::ShortToStateKey;
|
||||
|
||||
if let Some(id) =
|
||||
self.shortstatekey_cache.lock().unwrap().get_mut(&shortstatekey)
|
||||
{
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
return Ok(id.clone());
|
||||
}
|
||||
|
||||
let x = self.db.get_statekey_from_short(shortstatekey)?;
|
||||
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
|
||||
self.shortstatekey_cache
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(shortstatekey, x.clone());
|
||||
|
||||
Ok(x)
|
||||
}
|
||||
|
||||
/// Returns `(shortstatehash, already_existed)`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue