Skip to content

Commit

Permalink
Gateway is already cheaply clonable
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-lacroix committed May 19, 2024
1 parent b51566d commit 370fa19
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub async fn add_conda_specs_to_project(
spec_type,
platform,
grouped_environment.channels(),
project.repodata_gateway(),
&project.repodata_gateway(),

Check failure on line 307 in src/cli/add.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

this expression creates a reference which is immediately dereferenced by the compiler
)
.await
{
Expand Down
2 changes: 1 addition & 1 deletion src/lock_file/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ enum TaskResult {
async fn spawn_solve_conda_environment_task(
group: GroupedEnvironment<'_>,
existing_repodata_records: Arc<RepoDataRecordsByName>,
repodata_gateway: Arc<Gateway>,
repodata_gateway: Gateway,
platform: Platform,
concurrency_semaphore: Arc<Semaphore>,
client: reqwest::Client,
Expand Down
2 changes: 1 addition & 1 deletion src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub struct Project {
authenticated_client: ClientWithMiddleware,
/// The repodata gateway to use for answering queries about repodata.
/// This is wrapped in a `OnceLock` to allow for lazy initialization.
repodata_gateway: OnceLock<Arc<Gateway>>,
repodata_gateway: OnceLock<Gateway>,
/// The manifest for the project
pub(crate) manifest: Manifest,
/// The cache that contains environment variables
Expand Down
9 changes: 3 additions & 6 deletions src/project/repodata.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{config, project::Project};
use rattler_repodata_gateway::{ChannelConfig, Gateway, SourceConfig};
use std::path::PathBuf;
use std::sync::Arc;

impl Project {
/// Returns the [`Gateway`] used by this project.
pub fn repodata_gateway(&self) -> &Arc<Gateway> {
pub fn repodata_gateway(&self) -> &Gateway {
self.repodata_gateway.get_or_init(|| {
// Determine the cache directory and fall back to sane defaults otherwise.
let cache_dir = config::get_cache_dir().unwrap_or_else(|e| {
Expand All @@ -27,16 +26,14 @@ impl Project {
.unwrap_or_default();

// Construct the gateway
let gateway = Gateway::builder()
Gateway::builder()
.with_client(self.authenticated_client().clone())
.with_cache_dir(cache_dir.join("repodata"))
.with_channel_config(ChannelConfig {
default: default_source_config,
per_channel: Default::default(),
})
.finish();

Arc::new(gateway)
.finish()
})
}
}

0 comments on commit 370fa19

Please sign in to comment.