perf(backup): extract archive off the runtime

Run File::open, ZipArchive::new and the extraction of the backup
archive inside spawn_blocking. Extracting a multi-file backup blocked
a tokio worker for hundreds of milliseconds to seconds while the
runtime kept serving other work on the remaining workers.

Move the PROFILE_WRITE_LOCK acquisition after the extraction, right
before finalize_restored_verge_config: the lock protects the
config-data transition (extracted files reloaded into drafts), not the
plain filesystem writes, so profile operations no longer queue behind
the blocking unzip.
This commit is contained in:
Tunglies
2026-10-28 09:17:38 +08:00
parent 34607dce55
commit cefc0d8c62
+11 -3
View File
@@ -148,10 +148,18 @@ async fn restore_backup_archive(path: PathBuf) -> Result<()> {
)
};
let file = AsyncHandler::spawn_blocking(move || std::fs::File::open(&path)).await??;
let mut zip = zip::ZipArchive::new(file)?;
let home_dir = app_home_dir()?;
AsyncHandler::spawn_blocking(move || -> Result<()> {
let file = std::fs::File::open(&path)?;
let mut zip = zip::ZipArchive::new(file)?;
zip.extract(&home_dir)?;
Ok(())
})
.await
.map_err(|join| anyhow!("backup extraction task failed: {join}"))??;
// Held for the config-data transition only; extraction is plain filesystem work.
let _profile_write = crate::config::profiles::PROFILE_WRITE_LOCK.lock().await;
zip.extract(app_home_dir()?)?;
finalize_restored_verge_config(webdav_url, webdav_username, webdav_password).await
}