Fix per-host widget cache to prevent overwriting cached data
Only update widgets when metrics are available for the current host, preventing immediate overwrite of cached widget states when switching hosts.
This commit is contained in:
parent
4b7d08153c
commit
792ad066c9
@ -75,13 +75,15 @@ impl TuiApp {
|
||||
self.host_widgets.entry(hostname.to_string()).or_insert_with(HostWidgets::new)
|
||||
}
|
||||
|
||||
/// Update widgets with metrics from store
|
||||
/// Update widgets with metrics from store (only for current host)
|
||||
pub fn update_metrics(&mut self, metric_store: &MetricStore) {
|
||||
if let Some(hostname) = self.current_host.clone() {
|
||||
// Only update widgets if we have metrics for this host
|
||||
let all_metrics = metric_store.get_metrics_for_host(&hostname);
|
||||
if !all_metrics.is_empty() {
|
||||
// Get metrics first while hostname is borrowed
|
||||
let cpu_metrics = metric_store.get_metrics_for_widget(&hostname, WidgetType::Cpu);
|
||||
let memory_metrics = metric_store.get_metrics_for_widget(&hostname, WidgetType::Memory);
|
||||
let all_metrics = metric_store.get_metrics_for_host(&hostname);
|
||||
let service_metrics: Vec<&Metric> = all_metrics.iter()
|
||||
.filter(|m| m.name.starts_with("service_"))
|
||||
.copied()
|
||||
@ -102,6 +104,7 @@ impl TuiApp {
|
||||
host_widgets.last_update = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update available hosts
|
||||
pub fn update_hosts(&mut self, hosts: Vec<String>) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user