purges old pending push messages more efficiently (#12522)

This commit is contained in:
behzad nouri
2020-09-28 21:59:59 +00:00
committed by GitHub
parent 833ad20b01
commit c94fe9236f

View File

@ -370,34 +370,19 @@ impl CrdsGossipPush {
/// purge old pending push messages /// purge old pending push messages
pub fn purge_old_pending_push_messages(&mut self, crds: &Crds, min_time: u64) { pub fn purge_old_pending_push_messages(&mut self, crds: &Crds, min_time: u64) {
let old_msgs: Vec<CrdsValueLabel> = self self.push_messages.retain(|k, hash| {
.push_messages matches!(crds.lookup_versioned(k), Some(versioned) if
.iter() versioned.value.wallclock() >= min_time
.filter_map(|(k, hash)| { && versioned.value_hash == *hash)
if let Some(versioned) = crds.lookup_versioned(k) { });
if versioned.value.wallclock() < min_time || versioned.value_hash != *hash {
Some(k)
} else {
None
}
} else {
Some(k)
}
})
.cloned()
.collect();
for k in old_msgs {
self.push_messages.remove(&k);
}
} }
/// purge received push message cache /// purge received push message cache
pub fn purge_old_received_cache(&mut self, min_time: u64) { pub fn purge_old_received_cache(&mut self, min_time: u64) {
self.received_cache self.received_cache.retain(|_, v| {
.iter_mut() v.retain(|_, (_, t)| *t > min_time);
.for_each(|v| v.1.retain(|_, v| v.1 > min_time)); !v.is_empty()
});
self.received_cache.retain(|_, v| !v.is_empty());
} }
} }