From 28a66562a2fcf6a9fb1557b8014da83f32c22e1f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 9 Aug 2026 10:09:45 +0000 Subject: [PATCH] perf(storage): offload file pruning to background thread Moves the synchronous file I/O logic in `run_backups` to a background thread (`std::thread::spawn`) so that deleting old snapshots or deleted-sheets files does not block the main thread execution. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src-tauri/src/main.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 74c4642..4436f39 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -477,24 +477,28 @@ fn run_backups(app: AppHandle, dir: Option, retention_days: u32) -> Resu }) .collect(); snaps.sort(); - if snaps.len() > SNAPSHOT_KEEP { - for old in &snaps[..snaps.len() - SNAPSHOT_KEEP] { - fs::remove_file(old).ok(); - } - } - // prune the deleted-sheets bin by age - let cutoff = - SystemTime::now() - std::time::Duration::from_secs(u64::from(retention_days) * 86400); - if let Ok(entries) = fs::read_dir(bdir.join("deleted")) { - for entry in entries.flatten() { - if let Ok(meta) = entry.metadata() { - if meta.modified().map(|m| m < cutoff).unwrap_or(false) { - fs::remove_file(entry.path()).ok(); + std::thread::spawn(move || { + if snaps.len() > SNAPSHOT_KEEP { + for old in &snaps[..snaps.len() - SNAPSHOT_KEEP] { + fs::remove_file(old).ok(); + } + } + + // prune the deleted-sheets bin by age + let cutoff = + SystemTime::now() - std::time::Duration::from_secs(u64::from(retention_days) * 86400); + if let Ok(entries) = fs::read_dir(bdir.join("deleted")) { + for entry in entries.flatten() { + if let Ok(meta) = entry.metadata() { + if meta.modified().map(|m| m < cutoff).unwrap_or(false) { + fs::remove_file(entry.path()).ok(); + } } } } - } + }); + Ok(()) }