Skip to content
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

refactor: remove lazy_static where const functions are available #3526

Merged
merged 4 commits into from
Jan 23, 2024
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
8 changes: 2 additions & 6 deletions src/dfx/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use dfx_core::config::model::dfinity::CONFIG_FILE_NAME;
use dfx_core::json::{load_json_file, save_json_file};
use fn_error_context::context;
use indicatif::HumanBytes;
use lazy_static::lazy_static;
use semver::Version;
use serde_json::Value;
use slog::{info, warn, Logger};
Expand All @@ -30,15 +29,12 @@ const RELEASE_ROOT: &str = "https://sdk.dfinity.org";
// The dist-tag to use when getting the version from NPM.
const AGENT_JS_DEFAULT_INSTALL_DIST_TAG: &str = "latest";

lazy_static! {
// Tested on a phone tethering connection. This should be fine with
// little impact to the user, given that "new" is supposedly a
// heavy-weight operation. Thus, worst case we are utilizing the user
// expectation for the duration to have a more expensive version
// check.
static ref CHECK_VERSION_TIMEOUT: Duration = Duration::from_secs(2);

}
const CHECK_VERSION_TIMEOUT: Duration = Duration::from_secs(2);

/// Creates a new project.
#[derive(Parser)]
Expand Down Expand Up @@ -417,7 +413,7 @@ pub fn exec(env: &dyn Environment, opts: NewOpts) -> DfxResult {

// It is fine for the following command to timeout or fail. We
// drop the error.
let latest_version = get_latest_version(RELEASE_ROOT, Some(*CHECK_VERSION_TIMEOUT)).ok();
let latest_version = get_latest_version(RELEASE_ROOT, Some(CHECK_VERSION_TIMEOUT)).ok();

if is_upgrade_necessary(latest_version.as_ref(), current_version) {
warn_upgrade(log, latest_version.as_ref(), current_version);
Expand Down
7 changes: 2 additions & 5 deletions src/dfx/src/lib/info/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use lazy_static::lazy_static;
lazy_static! {
static ref REPLICA_REV_STR: String = env!("DFX_ASSET_REPLICA_REV").to_string();
}
const REPLICA_REV_STR: &str = env!("DFX_ASSET_REPLICA_REV");

pub fn replica_rev() -> &'static str {
&REPLICA_REV_STR
REPLICA_REV_STR
}
Loading