Skip to content

Avoid cloning Config struct #3560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/admin/render_readmes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
schema::{crates, readme_renderings, versions},
Config,
};
use std::{io::Read, path::Path, thread};
use std::{io::Read, path::Path, sync::Arc, thread};

use chrono::{TimeZone, Utc};
use clap::Clap;
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct Opts {
}

pub fn run(opts: Opts) {
let config = Config::default();
let config = Arc::new(Config::default());
let conn = db::connect_now().unwrap();

let start_time = Utc::now();
Expand Down
5 changes: 3 additions & 2 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();

let config = cargo_registry::Config::default();
let env = config.env;
let client = Client::new();
let app = Arc::new(App::new(config.clone(), Some(client)));
let app = Arc::new(App::new(config, Some(client)));

// Start the background thread periodically persisting download counts to the database.
downloads_counter_thread(app.clone());
Expand All @@ -63,7 +64,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let threads = dotenv::var("SERVER_THREADS")
.map(|s| s.parse().expect("SERVER_THREADS was not a valid number"))
.unwrap_or_else(|_| {
if config.env == Env::Development {
if env == Env::Development {
5
} else {
// A large default because this can be easily changed via env and in production we
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::publish_rate_limit::PublishRateLimit;
use crate::{env, uploaders::Uploader, Env, Replica};

#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct Config {
pub uploader: Uploader,
pub session_key: String,
Expand All @@ -24,7 +24,7 @@ pub struct Config {
pub metrics_authorization_token: Option<String>,
}

#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct DbPoolConfig {
pub url: String,
pub read_only_mode: bool,
Expand Down
6 changes: 3 additions & 3 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use crate::{App, Env};

pub fn build_middleware(app: Arc<App>, endpoints: RouteBuilder) -> MiddlewareBuilder {
let mut m = MiddlewareBuilder::new(endpoints);
let config = app.config.clone();
let env = config.env;
let env = app.config.env;
let blocked_traffic = app.config.blocked_traffic.clone();

if env != Env::Test {
m.add(ensure_well_formed_500::EnsureWellFormed500);
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn build_middleware(app: Arc<App>, endpoints: RouteBuilder) -> MiddlewareBui

m.around(Head::default());

for (header, blocked_values) in config.blocked_traffic {
for (header, blocked_values) in blocked_traffic {
m.around(block_traffic::BlockTraffic::new(header, blocked_values));
}

Expand Down