improvement: state info cache
This commit is contained in:
		
							parent
							
								
									5bd5b41c70
								
							
						
					
					
						commit
						a4310f840e
					
				
					 2 changed files with 24 additions and 0 deletions
				
			
		|  | @ -278,6 +278,7 @@ impl Database { | ||||||
|                 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 { | ||||||
|     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 @@ impl Rooms { | ||||||
|             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 @@ impl Rooms { | ||||||
| 
 | 
 | ||||||
|             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) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue