mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 23:51:59 +03:00
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:
parent
c958f30662
commit
28a66562a2
1 changed files with 18 additions and 14 deletions
|
|
@ -477,24 +477,28 @@ fn run_backups(app: AppHandle, dir: Option<String>, 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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue