mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
move eventidshort_cache to service
This commit is contained in:
parent
095ee483ac
commit
2b2b4169df
5 changed files with 49 additions and 39 deletions
|
|
@ -19,43 +19,26 @@ impl service::rooms::short::Data for KeyValueDatabase {
|
|||
fn get_or_create_shorteventid(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
) -> Result<ShortEventId> {
|
||||
let lookup = Lookup::CreateEventIdToShort;
|
||||
|
||||
if let Some(short) =
|
||||
self.eventidshort_cache.lock().unwrap().get_mut(event_id)
|
||||
{
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
return Ok(*short);
|
||||
}
|
||||
|
||||
let short = if let Some(shorteventid) =
|
||||
) -> Result<(ShortEventId, bool)> {
|
||||
let (short, created) = if let Some(shorteventid) =
|
||||
self.eventid_shorteventid.get(event_id.as_bytes())?
|
||||
{
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
let shorteventid =
|
||||
utils::u64_from_bytes(&shorteventid).map_err(|_| {
|
||||
Error::bad_database("Invalid shorteventid in db.")
|
||||
})?;
|
||||
|
||||
utils::u64_from_bytes(&shorteventid).map_err(|_| {
|
||||
Error::bad_database("Invalid shorteventid in db.")
|
||||
})?
|
||||
(shorteventid, false)
|
||||
} else {
|
||||
METRICS.record_lookup(lookup, FoundIn::Nothing);
|
||||
|
||||
let shorteventid = services().globals.next_count()?;
|
||||
self.eventid_shorteventid
|
||||
.insert(event_id.as_bytes(), &shorteventid.to_be_bytes())?;
|
||||
self.shorteventid_eventid
|
||||
.insert(&shorteventid.to_be_bytes(), event_id.as_bytes())?;
|
||||
shorteventid
|
||||
(shorteventid, true)
|
||||
};
|
||||
|
||||
let short = ShortEventId::new(short);
|
||||
|
||||
self.eventidshort_cache
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(event_id.to_owned(), short);
|
||||
|
||||
Ok(short)
|
||||
Ok((ShortEventId::new(short), created))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), fields(cache_result))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue