Skip to content
Snippets Groups Projects
Unverified Commit a4310f84 authored by Timo Kösters's avatar Timo Kösters
Browse files

improvement: state info cache

parent 5bd5b41c
No related branches found
No related tags found
No related merge requests found
...@@ -278,6 +278,7 @@ pub async fn load_or_create(config: &Config) -> Result<Arc<TokioRwLock<Self>>> { ...@@ -278,6 +278,7 @@ pub async fn load_or_create(config: &Config) -> Result<Arc<TokioRwLock<Self>>> {
pdu_cache: Mutex::new(LruCache::new(100_000)), pdu_cache: Mutex::new(LruCache::new(100_000)),
auth_chain_cache: Mutex::new(LruCache::new(100_000)), auth_chain_cache: Mutex::new(LruCache::new(100_000)),
shorteventid_cache: Mutex::new(LruCache::new(1_000_000)), shorteventid_cache: Mutex::new(LruCache::new(1_000_000)),
stateinfo_cache: Mutex::new(LruCache::new(1000)),
}, },
account_data: account_data::AccountData { account_data: account_data::AccountData {
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?, roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
......
...@@ -92,6 +92,13 @@ pub struct Rooms { ...@@ -92,6 +92,13 @@ pub struct Rooms {
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<u64, HashSet<u64>>>, pub(super) auth_chain_cache: Mutex<LruCache<u64, HashSet<u64>>>,
pub(super) shorteventid_cache: Mutex<LruCache<u64, EventId>>, pub(super) shorteventid_cache: Mutex<LruCache<u64, EventId>>,
pub(super) stateinfo_cache: Mutex<LruCache<u64,
Vec<(
u64, // sstatehash
HashSet<CompressedStateEvent>, // full state
HashSet<CompressedStateEvent>, // added
HashSet<CompressedStateEvent>, // removed
)>>>,
} }
impl Rooms { impl Rooms {
...@@ -407,6 +414,14 @@ pub fn load_shortstatehash_info( ...@@ -407,6 +414,14 @@ pub fn load_shortstatehash_info(
HashSet<CompressedStateEvent>, // removed HashSet<CompressedStateEvent>, // removed
)>, )>,
> { > {
if let Some(r) = self.stateinfo_cache
.lock()
.unwrap()
.get_mut(&shortstatehash)
{
return Ok(r.clone());
}
let value = self let value = self
.shortstatehash_statediff .shortstatehash_statediff
.get(&shortstatehash.to_be_bytes())? .get(&shortstatehash.to_be_bytes())?
...@@ -443,10 +458,18 @@ pub fn load_shortstatehash_info( ...@@ -443,10 +458,18 @@ pub fn load_shortstatehash_info(
response.push((shortstatehash, state, added, removed)); response.push((shortstatehash, state, added, removed));
self.stateinfo_cache
.lock()
.unwrap()
.insert(shortstatehash, response.clone());
Ok(response) Ok(response)
} else { } else {
let mut response = Vec::new(); let mut response = Vec::new();
response.push((shortstatehash, added.clone(), added, removed)); response.push((shortstatehash, added.clone(), added, removed));
self.stateinfo_cache
.lock()
.unwrap()
.insert(shortstatehash, response.clone());
Ok(response) Ok(response)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment