Skip to content

Commit 9a05e38

Browse files
committed
replace some arcs with ref
1 parent 24b5bbe commit 9a05e38

File tree

5 files changed

+20
-39
lines changed

5 files changed

+20
-39
lines changed

src/bin/cratesfyi.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,24 +205,17 @@ impl CommandLine {
205205

206206
start_background_metrics_webserver(Some(metric_server_socket_addr), &ctx)?;
207207

208-
ctx.runtime.block_on(async {
209-
docs_rs::utils::watch_registry(
210-
ctx.async_build_queue.clone(),
211-
ctx.config.clone(),
212-
ctx.index.clone(),
213-
)
214-
.await
208+
ctx.runtime.block_on(async move {
209+
docs_rs::utils::watch_registry(&ctx.async_build_queue, &ctx.config, ctx.index)
210+
.await
215211
})?;
216212
}
217213
Self::StartBuildServer {
218214
metric_server_socket_addr,
219215
} => {
220216
start_background_metrics_webserver(Some(metric_server_socket_addr), &ctx)?;
221217

222-
let build_queue = ctx.build_queue.clone();
223-
let config = ctx.config.clone();
224-
let rustwide_builder = RustwideBuilder::init(&ctx)?;
225-
queue_builder(&ctx, rustwide_builder, build_queue, config)?;
218+
queue_builder(&ctx, RustwideBuilder::init(&ctx)?)?;
226219
}
227220
Self::StartWebServer { socket_addr } => {
228221
// Blocks indefinitely
@@ -654,14 +647,8 @@ impl DatabaseSubcommand {
654647
.runtime
655648
.block_on(async move {
656649
let mut conn = ctx.pool.get_async().await?;
657-
db::delete_version(
658-
&mut conn,
659-
&ctx.async_storage,
660-
&ctx.config,
661-
&name,
662-
&version,
663-
)
664-
.await
650+
db::delete_version(&mut conn, &ctx.async_storage, &ctx.config, &name, &version)
651+
.await
665652
})
666653
.context("failed to delete the version")?,
667654
Self::Delete {

src/cdn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum CdnBackend {
5151
}
5252

5353
impl CdnBackend {
54-
pub async fn new(config: &Arc<Config>) -> CdnBackend {
54+
pub async fn new(config: &Config) -> CdnBackend {
5555
match config.cdn_backend {
5656
CdnKind::CloudFront => {
5757
let shared_config = aws_config::load_defaults(BehaviorVersion::latest()).await;

src/storage/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ impl AsyncStorage {
187187
config: Arc<Config>,
188188
) -> Result<Self> {
189189
Ok(Self {
190-
config: config.clone(),
191190
backend: match config.storage_backend {
192191
StorageKind::Database => {
193192
StorageBackend::Database(DatabaseBackend::new(pool, metrics))
@@ -196,6 +195,7 @@ impl AsyncStorage {
196195
StorageBackend::S3(Box::new(S3Backend::new(metrics, &config).await?))
197196
}
198197
},
198+
config,
199199
})
200200
}
201201

src/utils/daemon.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use tracing::{debug, info};
1919
/// NOTE: this should only be run once, otherwise crates would be added
2020
/// to the queue multiple times.
2121
pub async fn watch_registry(
22-
build_queue: Arc<AsyncBuildQueue>,
23-
config: Arc<Config>,
22+
build_queue: &AsyncBuildQueue,
23+
config: &Config,
2424
index: Arc<Index>,
2525
) -> Result<(), Error> {
2626
let mut last_gc = Instant::now();
@@ -56,13 +56,12 @@ fn start_registry_watcher(context: &Context) -> Result<(), Error> {
5656
let build_queue = context.async_build_queue.clone();
5757
let config = context.config.clone();
5858
let index = context.index.clone();
59-
let runtime = context.runtime.clone();
6059

61-
runtime.spawn(async {
60+
context.runtime.spawn(async move {
6261
// space this out to prevent it from clashing against the queue-builder thread on launch
6362
tokio::time::sleep(Duration::from_secs(30)).await;
6463

65-
watch_registry(build_queue, config, index).await
64+
watch_registry(&build_queue, &config, index).await
6665
});
6766

6867
Ok(())
@@ -195,14 +194,12 @@ pub fn start_daemon(context: Context, enable_registry_watcher: bool) -> Result<(
195194
}
196195

197196
// build new crates every minute
198-
let build_queue = context.build_queue.clone();
199-
let config = context.config.clone();
200197
let rustwide_builder = RustwideBuilder::init(&context)?;
201198
thread::Builder::new()
202199
.name("build queue reader".to_string())
203200
.spawn({
204201
let context = context.clone();
205-
move || queue_builder(&context, rustwide_builder, build_queue, config).unwrap()
202+
move || queue_builder(&context, rustwide_builder).unwrap()
206203
})
207204
.unwrap();
208205

src/utils/queue_builder.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
use crate::Context;
2-
use crate::{BuildQueue, Config, docbuilder::RustwideBuilder, utils::report_error};
2+
use crate::{docbuilder::RustwideBuilder, utils::report_error};
33
use anyhow::{Context as _, Error};
44
use std::panic::{AssertUnwindSafe, catch_unwind};
5-
use std::sync::Arc;
65
use std::time::Duration;
76
use std::{fs, io, path::Path, thread};
87
use tracing::{debug, error, warn};
98

10-
pub fn queue_builder(
11-
context: &Context,
12-
mut builder: RustwideBuilder,
13-
build_queue: Arc<BuildQueue>,
14-
config: Arc<Config>,
15-
) -> Result<(), Error> {
9+
pub fn queue_builder(context: &Context, mut builder: RustwideBuilder) -> Result<(), Error> {
1610
loop {
17-
if let Err(e) = remove_tempdirs(&config.temp_dir) {
11+
let temp_dir = &context.config.temp_dir;
12+
if let Err(e) = remove_tempdirs(temp_dir) {
1813
report_error(&anyhow::anyhow!(e).context(format!(
1914
"failed to clean temporary directory {:?}",
20-
&config.temp_dir
15+
temp_dir
2116
)));
2217
}
2318

19+
let build_queue = &context.build_queue;
20+
2421
// check lock file
2522
match build_queue.is_locked().context("could not get queue lock") {
2623
Ok(true) => {

0 commit comments

Comments
 (0)