perf(storage): offload file pruning to background thread

Moves the synchronous file I/O logic in `run_backups` to a background thread (`std:🧵: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>
This commit is contained in:
google-labs-jules[bot] 2026-08-09 10:09:45 +00:00
parent c958f30662
commit 28a66562a2

View file

@ -477,24 +477,28 @@ fn run_backups(app: AppHandle, dir: Option<String>, retention_days: u32) -> Resu
}) })
.collect(); .collect();
snaps.sort(); 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 std::thread::spawn(move || {
let cutoff = if snaps.len() > SNAPSHOT_KEEP {
SystemTime::now() - std::time::Duration::from_secs(u64::from(retention_days) * 86400); for old in &snaps[..snaps.len() - SNAPSHOT_KEEP] {
if let Ok(entries) = fs::read_dir(bdir.join("deleted")) { fs::remove_file(old).ok();
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(); // 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(()) Ok(())
} }