Cleanup/remove a couple more unwraps

This commit is contained in:
Herbert Wolverson 2024-07-17 08:35:16 -05:00
parent 5e94c879de
commit 50042d79ea
2 changed files with 17 additions and 16 deletions

View File

@ -46,8 +46,7 @@ pub async fn circuit_capacity(channels: Arc<PubSub>) {
});
// Map circuits to capacities
let capacities: Vec<Capacity> = {
let shaped_devices = SHAPED_DEVICES.read().unwrap();
let capacities: Vec<Capacity> = if let Ok(shaped_devices) = SHAPED_DEVICES.read() {
circuits.iter().filter_map(|(circuit_id, accumulator)| {
if let Some(device) = shaped_devices.devices.iter().find(|sd| sd.circuit_id == *circuit_id) {
let down_mbps = (accumulator.bytes.down as f64 * 8.0) / 1_000_000.0;
@ -65,6 +64,8 @@ pub async fn circuit_capacity(channels: Arc<PubSub>) {
None
}
}).collect()
} else {
Vec::new()
};
let message = json!(

View File

@ -29,20 +29,20 @@ impl From<&IpStats> for IpStatsWithPlan {
};
if !result.circuit_id.is_empty() {
if let Some(circuit) = SHAPED_DEVICES
.read()
.unwrap()
.devices
.iter()
.find(|sd| sd.circuit_id == result.circuit_id)
{
let name = if circuit.circuit_name.len() > 20 {
&circuit.circuit_name[0..20]
} else {
&circuit.circuit_name
};
result.ip_address = format!("{} ({})", name, result.ip_address);
result.plan = DownUpOrder::new(circuit.download_max_mbps, circuit.upload_max_mbps);
if let Ok(shaped_devices_reader) = SHAPED_DEVICES.read() {
if let Some(circuit) = shaped_devices_reader
.devices
.iter()
.find(|sd| sd.circuit_id == result.circuit_id)
{
let name = if circuit.circuit_name.len() > 20 {
&circuit.circuit_name[0..20]
} else {
&circuit.circuit_name
};
result.ip_address = format!("{} ({})", name, result.ip_address);
result.plan = DownUpOrder::new(circuit.download_max_mbps, circuit.upload_max_mbps);
}
}
}