Ensure we don't have more than `max_subnets` number of subnets in the cache. Returns the removed subnet IDs.
(&mut self)
| 147 | /// |
| 148 | /// Returns the removed subnet IDs. |
| 149 | fn prune_subnets(&mut self) -> HashSet<SubnetID> { |
| 150 | let mut removed_subnet_ids = HashSet::new(); |
| 151 | |
| 152 | let to_prune = self.subnet_providers.len().saturating_sub(self.max_subnets); |
| 153 | if to_prune > 0 { |
| 154 | let mut counts = self |
| 155 | .subnet_providers |
| 156 | .iter() |
| 157 | .map(|(id, ps)| (id.clone(), ps.len())) |
| 158 | .collect::<Vec<_>>(); |
| 159 | |
| 160 | counts.sort_by_key(|(_, count)| *count); |
| 161 | |
| 162 | for (subnet_id, _) in counts { |
| 163 | if self.pinned_subnets.contains(&subnet_id) { |
| 164 | continue; |
| 165 | } |
| 166 | self.subnet_providers.remove(&subnet_id); |
| 167 | removed_subnet_ids.insert(subnet_id); |
| 168 | if removed_subnet_ids.len() == to_prune { |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | removed_subnet_ids |
| 175 | } |
| 176 | |
| 177 | /// Prune any provider which hasn't provided an update since a cutoff timestamp. |
| 178 | /// |
no test coverage detected