mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
move pdu_cache to service
This commit is contained in:
parent
fb534d8140
commit
7563360bee
6 changed files with 44 additions and 40 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue