move pdu_cache to service

This commit is contained in:
Charles Hall 2024-09-30 20:37:50 -07:00
parent fb534d8140
commit 7563360bee
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
6 changed files with 44 additions and 40 deletions

View file

@ -132,14 +132,7 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
#[tracing::instrument(skip(self))]
fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> {
let lookup = Lookup::Pdu;
if let Some(p) = self.pdu_cache.lock().unwrap().get_mut(event_id) {
METRICS.record_lookup(lookup, FoundIn::Cache);
return Ok(Some(Arc::clone(p)));
}
if let Some(pdu) = self
Ok(self
.get_non_outlier_pdu(event_id)?
.map_or_else(
|| {
@ -154,18 +147,7 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
},
|x| Ok(Some(x)),
)?
.map(Arc::new)
{
METRICS.record_lookup(lookup, FoundIn::Database);
self.pdu_cache
.lock()
.unwrap()
.insert(event_id.to_owned(), Arc::clone(&pdu));
Ok(Some(pdu))
} else {
METRICS.record_lookup(lookup, FoundIn::Nothing);
Ok(None)
}
.map(Arc::new))
}
/// Returns the pdu.
@ -241,7 +223,6 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
&self,
pdu_id: &PduId,
pdu_json: &CanonicalJsonObject,
pdu: &PduEvent,
) -> Result<()> {
if self.pduid_pdu.get(pdu_id.as_bytes())?.is_some() {
self.pduid_pdu.insert(
@ -256,8 +237,6 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
));
}
self.pdu_cache.lock().unwrap().remove(&(*pdu.event_id).to_owned());
Ok(())
}