Remove unused code and eliminate build warnings

Removed unused widget subscription system, cache utilities, error variants,
theme functions, and struct fields. Replaced subscription-based widgets
with direct metric filtering. Build now completes with zero warnings.
This commit is contained in:
2025-10-18 23:50:15 +02:00
parent 7f85a6436e
commit 0141a6e111
14 changed files with 15 additions and 764 deletions

View File

@@ -1,74 +0,0 @@
use super::{Collector, CollectorError};
use crate::cache::MetricCacheManager;
use cm_dashboard_shared::Metric;
use async_trait::async_trait;
use std::sync::Arc;
use tracing::{debug, instrument};
/// Wrapper that adds caching to any collector
pub struct CachedCollector {
name: String,
inner: Box<dyn Collector>,
cache_manager: Arc<MetricCacheManager>,
}
impl CachedCollector {
pub fn new(
name: String,
inner: Box<dyn Collector>,
cache_manager: Arc<MetricCacheManager>
) -> Self {
Self {
name,
inner,
cache_manager,
}
}
}
#[async_trait]
impl Collector for CachedCollector {
fn name(&self) -> &str {
&self.name
}
#[instrument(skip(self), fields(collector = %self.name))]
async fn collect(&self) -> Result<Vec<Metric>, CollectorError> {
// First, get all metrics this collector would normally produce
let all_metrics = self.inner.collect().await?;
let mut result_metrics = Vec::new();
let mut metrics_to_collect = Vec::new();
// Check cache for each metric
for metric in all_metrics {
if let Some(cached_metric) = self.cache_manager.get_cached_metric(&metric.name).await {
// Use cached version
result_metrics.push(cached_metric);
debug!("Using cached metric: {}", metric.name);
} else {
// Need to collect this metric
metrics_to_collect.push(metric.name.clone());
result_metrics.push(metric);
}
}
// Cache the newly collected metrics
for metric in &result_metrics {
if metrics_to_collect.contains(&metric.name) {
self.cache_manager.cache_metric(metric.clone()).await;
debug!("Cached new metric: {} (tier: {}s)",
metric.name,
self.cache_manager.get_cache_interval(&metric.name));
}
}
if !metrics_to_collect.is_empty() {
debug!("Collected {} new metrics, used {} cached metrics",
metrics_to_collect.len(),
result_metrics.len() - metrics_to_collect.len());
}
Ok(result_metrics)
}
}

View File

@@ -7,16 +7,4 @@ pub enum CollectorError {
#[error("Failed to parse value '{value}': {error}")]
Parse { value: String, error: String },
#[error("System command failed: {command}: {error}")]
CommandFailed { command: String, error: String },
#[error("Configuration error: {message}")]
Configuration { message: String },
#[error("Metric calculation error: {message}")]
Calculation { message: String },
#[error("Timeout error: operation took longer than {timeout_ms}ms")]
Timeout { timeout_ms: u64 },
}

View File

@@ -2,7 +2,6 @@ use async_trait::async_trait;
use cm_dashboard_shared::Metric;
use std::time::Duration;
pub mod cached_collector;
pub mod cpu;
pub mod memory;
pub mod disk;