From 50042d79ea44ad6fe0726ab2c700caae242f0f0e Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Wed, 17 Jul 2024 08:35:16 -0500 Subject: [PATCH] Cleanup/remove a couple more unwraps --- .../ws/ticker/circuit_capacity.rs | 5 ++-- .../ws/ticker/ipstats_conversion.rs | 28 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/rust/lqosd/src/node_manager/ws/ticker/circuit_capacity.rs b/src/rust/lqosd/src/node_manager/ws/ticker/circuit_capacity.rs index a7a41ccd..9e7db9f5 100644 --- a/src/rust/lqosd/src/node_manager/ws/ticker/circuit_capacity.rs +++ b/src/rust/lqosd/src/node_manager/ws/ticker/circuit_capacity.rs @@ -46,8 +46,7 @@ pub async fn circuit_capacity(channels: Arc) { }); // Map circuits to capacities - let capacities: Vec = { - let shaped_devices = SHAPED_DEVICES.read().unwrap(); + let capacities: Vec = 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) { None } }).collect() + } else { + Vec::new() }; let message = json!( diff --git a/src/rust/lqosd/src/node_manager/ws/ticker/ipstats_conversion.rs b/src/rust/lqosd/src/node_manager/ws/ticker/ipstats_conversion.rs index cace374d..baf0da14 100644 --- a/src/rust/lqosd/src/node_manager/ws/ticker/ipstats_conversion.rs +++ b/src/rust/lqosd/src/node_manager/ws/ticker/ipstats_conversion.rs @@ -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); + } } }