mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Cleanup/remove a couple more unwraps
This commit is contained in:
parent
5e94c879de
commit
50042d79ea
@ -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!(
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user