optimizations
This commit is contained in:
parent
64f5115d54
commit
99d4b94e5c
6 changed files with 54 additions and 48 deletions
|
|
@ -7,28 +7,35 @@ use crate::data::{
|
|||
status_page::model::StatusPageResponse,
|
||||
};
|
||||
|
||||
pub fn unify_data<'a>(status_page: &'a StatusPageResponse, heartbeat: &'a HeartbeatResponse) -> UnifiedData<'a> {
|
||||
pub fn unify_data<'a>(
|
||||
status_page: &'a StatusPageResponse,
|
||||
heartbeat: &'a HeartbeatResponse,
|
||||
) -> UnifiedData<'a> {
|
||||
let mut groups = Vec::with_capacity(status_page.public_group_list.len());
|
||||
let heartbeat_map: HashMap<u64, &'a [HeartbeatEntry]> = heartbeat
|
||||
.monitors
|
||||
.iter()
|
||||
.map(|m| (m.monitor_id, &m.heartbeats[..]))
|
||||
.collect();
|
||||
|
||||
let uptime_map: HashMap<(u64, u32), &'a UptimeData> = heartbeat
|
||||
.uptime_data
|
||||
.iter()
|
||||
.map(|u| ((u.monitor_id, u.period_hours), u))
|
||||
.collect();
|
||||
let mut heartbeat_map: HashMap<u64, &'a [HeartbeatEntry]> =
|
||||
HashMap::with_capacity(heartbeat.monitors.len());
|
||||
heartbeat_map.extend(
|
||||
heartbeat
|
||||
.monitors
|
||||
.iter()
|
||||
.map(|m| (m.monitor_id, &m.heartbeats[..])),
|
||||
);
|
||||
|
||||
let mut uptime_map: HashMap<(u64, u32), &'a UptimeData> =
|
||||
HashMap::with_capacity(heartbeat.uptime_data.len());
|
||||
uptime_map.extend(
|
||||
heartbeat
|
||||
.uptime_data
|
||||
.iter()
|
||||
.map(|u| ((u.monitor_id, u.period_hours), u)),
|
||||
);
|
||||
|
||||
for group in &status_page.public_group_list {
|
||||
let mut monitors = Vec::with_capacity(group.monitor_list.len());
|
||||
for monitor_info in &group.monitor_list {
|
||||
let uptime_data = uptime_map.get(&(monitor_info.id, 24)).copied();
|
||||
let heartbeats = heartbeat_map
|
||||
.get(&monitor_info.id)
|
||||
.copied()
|
||||
.unwrap_or(&[]);
|
||||
let heartbeats = heartbeat_map.get(&monitor_info.id).copied().unwrap_or(&[]);
|
||||
|
||||
let name: Cow<'a, str> = if monitor_info.name.len() > 100 {
|
||||
Cow::Owned(monitor_info.name.clone())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue