move shortstatekey_cache to service

This commit is contained in:
Charles Hall 2024-10-08 13:38:12 -07:00
parent 190b788683
commit d3b62e598d
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
4 changed files with 35 additions and 35 deletions

View file

@ -4,7 +4,6 @@ use ruma::{events::StateEventType, EventId, RoomId};
use crate::{
database::KeyValueDatabase,
observability::{FoundIn, Lookup, METRICS},
service::{
self,
rooms::short::{
@ -130,15 +129,6 @@ impl service::rooms::short::Data for KeyValueDatabase {
&self,
shortstatekey: ShortStateKey,
) -> Result<(StateEventType, String)> {
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 bytes = self
.shortstatekey_statekey
.get(&shortstatekey.get().to_be_bytes())?
@ -168,16 +158,7 @@ impl service::rooms::short::Data for KeyValueDatabase {
)
})?;
let result = (event_type, state_key);
METRICS.record_lookup(lookup, FoundIn::Database);
self.shortstatekey_cache
.lock()
.unwrap()
.insert(shortstatekey, result.clone());
Ok(result)
Ok((event_type, state_key))
}
/// Returns `(shortstatehash, already_existed)`