HasMap optimizationa
This commit is contained in:
parent
6af471ecca
commit
ef374723b2
2 changed files with 22 additions and 16 deletions
|
|
@ -1,21 +1,33 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::core::models::{UnifiedData, UnifiedGroupData, UnifiedMonitorData};
|
||||
use crate::data::heartbeat::model::HeartbeatResponse;
|
||||
use crate::data::status_page::model::StatusPageResponse;
|
||||
use crate::data::{
|
||||
heartbeat::model::{HeartbeatEntry, HeartbeatResponse, UptimeData},
|
||||
status_page::model::StatusPageResponse,
|
||||
};
|
||||
|
||||
pub fn unify_data(status_page: &StatusPageResponse, heartbeat: &HeartbeatResponse) -> UnifiedData {
|
||||
let mut groups = Vec::new();
|
||||
let heartbeat_map: HashMap<u64, Vec<HeartbeatEntry>> = heartbeat
|
||||
.monitors
|
||||
.iter()
|
||||
.map(|m| (m.monitor_id, m.heartbeats.clone()))
|
||||
.collect();
|
||||
|
||||
let uptime_map: HashMap<(u64, u32), UptimeData> = heartbeat
|
||||
.uptime_data
|
||||
.iter()
|
||||
.map(|u| ((u.monitor_id, u.period_hours), u.clone()))
|
||||
.collect();
|
||||
|
||||
for group in &status_page.public_group_list {
|
||||
let mut monitors = Vec::new();
|
||||
for monitor_info in &group.monitor_list {
|
||||
let uptime_data = heartbeat.get_uptime(monitor_info.id, 24).cloned();
|
||||
|
||||
let heartbeats = heartbeat
|
||||
.monitors
|
||||
.iter()
|
||||
.find(|m| m.monitor_id == monitor_info.id)
|
||||
.map(|m| m.heartbeats.clone())
|
||||
.unwrap_or_else(Vec::new);
|
||||
let uptime_data = uptime_map.get(&(monitor_info.id, 24)).cloned();
|
||||
let heartbeats = heartbeat_map
|
||||
.get(&monitor_info.id)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
|
||||
monitors.push(UnifiedMonitorData {
|
||||
monitor_info: monitor_info.clone(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue