about summary refs log tree commit diff
path: root/tvix/store/src/bin/tvix-store.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-05-25T05·43+0300
committerflokli <flokli@flokli.de>2023-05-25T12·35+0000
commita4d0a80466016281c3f2b90a1ade66338d258153 (patch)
tree63054780f1a0626c58c8141ad64e42b899c75bde /tvix/store/src/bin/tvix-store.rs
parent22776280b59f1efa0b63bd7efa6612a3827f8c65 (diff)
refactor(tvix/store/bin): instantiating TvixStoreIO once r/6206
Instead of instantiating it once in every loop iteration, put it in an
Arc, and clone that before passing it to the spawned task.

Change-Id: I5d9c838f27048726166fa50206d1edd5ed6849b5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8632
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src/bin/tvix-store.rs')
-rw-r--r--tvix/store/src/bin/tvix-store.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs
index feda586fcb46..5912c6464bfe 100644
--- a/tvix/store/src/bin/tvix-store.rs
+++ b/tvix/store/src/bin/tvix-store.rs
@@ -2,6 +2,7 @@ use clap::Subcommand;
 use data_encoding::BASE64;
 use std::io;
 use std::path::PathBuf;
+use std::sync::Arc;
 use tracing_subscriber::prelude::*;
 use tvix_store::blobservice::SledBlobService;
 use tvix_store::directoryservice::SledDirectoryService;
@@ -129,18 +130,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
                 directory_service.clone(),
             );
 
+            let io = Arc::new(TvixStoreIO::new(
+                blob_service,
+                directory_service,
+                path_info_service,
+                nar_calculation_service,
+            ));
+
             for path in paths {
                 let path_move = path.clone();
-
-                let mut io = TvixStoreIO::new(
-                    blob_service.clone(),
-                    directory_service.clone(),
-                    path_info_service.clone(),
-                    nar_calculation_service.clone(),
-                );
-
+                let io_move = io.clone();
                 let path_info = tokio::task::spawn_blocking(move || {
-                    io.import_path_with_pathinfo(&path_move)
+                    io_move
+                        .import_path_with_pathinfo(&path_move)
                         .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
                 })
                 .await??;