Add history pruning with configurable max entries and max days
- Add history_max_entries (default 50) and history_max_days (default 30) to AppConfig - Add prune() method to HistoryStore that removes old entries by age and count limits - Call prune after each history entry is added in the GUI - Preserve history settings through settings dialog save/load cycle
This commit is contained in:
@@ -17,6 +17,8 @@ pub struct AppConfig {
|
||||
pub high_contrast: bool,
|
||||
pub large_text: bool,
|
||||
pub reduced_motion: bool,
|
||||
pub history_max_entries: usize,
|
||||
pub history_max_days: u32,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
@@ -36,6 +38,8 @@ impl Default for AppConfig {
|
||||
high_contrast: false,
|
||||
large_text: false,
|
||||
reduced_motion: false,
|
||||
history_max_entries: 50,
|
||||
history_max_days: 30,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +272,32 @@ impl HistoryStore {
|
||||
self.write_all(&entries)
|
||||
}
|
||||
|
||||
pub fn prune(&self, max_entries: usize, max_days: u32) -> Result<()> {
|
||||
let mut entries = self.list()?;
|
||||
if entries.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let now_secs = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
let cutoff_secs = now_secs.saturating_sub(max_days as u64 * 86400);
|
||||
|
||||
// Remove entries older than max_days
|
||||
entries.retain(|e| {
|
||||
e.timestamp.parse::<u64>().unwrap_or(0) >= cutoff_secs
|
||||
});
|
||||
|
||||
// Trim to max_entries (keep the most recent)
|
||||
if entries.len() > max_entries {
|
||||
let start = entries.len() - max_entries;
|
||||
entries = entries.split_off(start);
|
||||
}
|
||||
|
||||
self.write_all(&entries)
|
||||
}
|
||||
|
||||
pub fn list(&self) -> Result<Vec<HistoryEntry>> {
|
||||
if !self.history_path.exists() {
|
||||
return Ok(Vec::new());
|
||||
|
||||
Reference in New Issue
Block a user