diff --git a/src/dns_cache.rs b/src/dns_cache.rs index a2359aa..a7a5bac 100644 --- a/src/dns_cache.rs +++ b/src/dns_cache.rs @@ -372,18 +372,19 @@ impl DnsCache { pub(crate) fn refresh_due_srv(&mut self, ty_domain: &str) -> (HashSet, HashSet) { let now = current_time_millis(); - let mut instances = vec![]; - - // find instance names for ty_domain. - for record in self.ptr.get_mut(ty_domain).into_iter().flatten() { - if record.get_record().is_expired(now) { - continue; - } - - if let Some(ptr) = record.any().downcast_ref::() { - instances.push(ptr.alias.clone()); - } - } + let instances: Vec<&String> = self + .ptr + .get(ty_domain) + .into_iter() + .flatten() + .filter(|record| !record.get_record().is_expired(now)) + .filter_map(|record| { + record + .any() + .downcast_ref::() + .map(|ptr| &ptr.alias) + }) + .collect(); // Check SRV records. let mut refresh_due = HashSet::new(); @@ -391,14 +392,14 @@ impl DnsCache { for instance in instances { let refresh_timers: HashSet = self .srv - .get_mut(&instance) + .get_mut(instance) .into_iter() .flatten() .filter_map(|record| record.updated_refresh_time(now)) .collect(); if !refresh_timers.is_empty() { - refresh_due.insert(instance); + refresh_due.insert(instance.clone()); new_timers.extend(refresh_timers); } } @@ -411,25 +412,26 @@ impl DnsCache { pub(crate) fn refresh_due_hosts(&mut self, ty_domain: &str) -> (HashSet, HashSet) { let now = current_time_millis(); - let mut instances = vec![]; - - // find instance names for ty_domain. - for record in self.ptr.get_mut(ty_domain).into_iter().flatten() { - if record.get_record().is_expired(now) { - continue; - } - - if let Some(ptr) = record.any().downcast_ref::() { - instances.push(ptr.alias.clone()); - } - } + let instances: Vec<&String> = self + .ptr + .get(ty_domain) + .into_iter() + .flatten() + .filter(|record| !record.get_record().is_expired(now)) + .filter_map(|record| { + record + .any() + .downcast_ref::() + .map(|ptr| &ptr.alias) + }) + .collect(); // Collect hostnames we have browsers for by SRV records. let mut hostnames_browsed = HashSet::new(); for instance in instances { let hosts: HashSet = self .srv - .get(&instance) + .get(instance) .into_iter() .flatten() .filter_map(|record| {