From 692de46e0a4200ea1a2b3525acbd35c473e2cb9e Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 19 Nov 2023 15:21:44 +0700 Subject: [PATCH 1/2] perf(tarball): use tokio::task::spawn_blocking --- crates/tarball/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tarball/src/lib.rs b/crates/tarball/src/lib.rs index c182ff4a..7ab4802d 100644 --- a/crates/tarball/src/lib.rs +++ b/crates/tarball/src/lib.rs @@ -200,7 +200,7 @@ impl<'a> DownloadTarballToStore<'a> { Checksum(ssri::Error), Other(TarballError), } - let cas_paths = tokio::task::spawn(async move { + let cas_paths = tokio::task::spawn_blocking(move || { verify_checksum(&response, package_integrity.clone()).map_err(TaskError::Checksum)?; // TODO: move tarball extraction to its own function From c9a454af88b363e026d98e53e04fb0dbe46be08f Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 19 Nov 2023 15:48:08 +0700 Subject: [PATCH 2/2] refactor: remove unnecessary function --- crates/tarball/src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/tarball/src/lib.rs b/crates/tarball/src/lib.rs index c182ff4a..626aa28b 100644 --- a/crates/tarball/src/lib.rs +++ b/crates/tarball/src/lib.rs @@ -17,7 +17,7 @@ use pacquet_store_dir::{ }; use pipe_trait::Pipe; use reqwest::Client; -use ssri::{Integrity, IntegrityChecker}; +use ssri::Integrity; use tar::Archive; use tokio::sync::{Notify, RwLock}; use tracing::instrument; @@ -103,11 +103,6 @@ fn decompress_gzip(gz_data: &[u8], unpacked_size: Option) -> Result Result { - integrity.pipe(IntegrityChecker::new).chain(data).result() -} - /// This subroutine downloads and extracts a tarball to the store directory. /// /// It returns a CAS map of files in the tarball. @@ -201,7 +196,7 @@ impl<'a> DownloadTarballToStore<'a> { Other(TarballError), } let cas_paths = tokio::task::spawn(async move { - verify_checksum(&response, package_integrity.clone()).map_err(TaskError::Checksum)?; + package_integrity.check(&response).map_err(TaskError::Checksum)?; // TODO: move tarball extraction to its own function // TODO: test it