use tracing::{debug, info};
use crate::selector::server_stat_man::ServerStatMan;
use super::types::SessionPersistence;
impl SessionPersistence {
pub async fn save_server_stats(&self, stat_man: &ServerStatMan) -> Result<usize, String> {
let stat_file = self.session_dir.join("server-stat.json");
let saved = stat_man.save_to_file_async(&stat_file).await?;
if saved > 0 {
debug!(
count = saved,
path = %stat_file.display(),
"Server statistics saved"
);
}
Ok(saved)
}
pub async fn load_server_stats(&self, stat_man: &ServerStatMan) -> Result<usize, String> {
let stat_file = self.session_dir.join("server-stat.json");
if !stat_file.exists() {
debug!("No server statistics file found, starting fresh");
return Ok(0);
}
let loaded = stat_man.load_from_file_async(&stat_file).await?;
if loaded > 0 {
info!(
count = loaded,
path = %stat_file.display(),
"Server statistics loaded from previous session"
);
}
Ok(loaded)
}
}