refactor(tvix/store/bin): instantiating TvixStoreIO once

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>
This commit is contained in:
Florian Klink 2023-05-25 08:43:52 +03:00 committed by flokli
parent 22776280b5
commit a4d0a80466

View file

@ -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??;