Skip to content

Commit

Permalink
Merge pull request #1898 from Urgau/remove-lazy_static
Browse files Browse the repository at this point in the history
Replace `lazy_static` with `LazyLock`
  • Loading branch information
Kobzol authored Feb 12, 2025
2 parents 8202b81 + 5e66716 commit 22fba5d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 35 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ openssl = "0.10"
dotenv = "0.15"
reqwest = { version = "0.11.4", features = ["json", "blocking"] }
regex = "1"
lazy_static = "1"
anyhow = "1"
hex = "0.4"
parser = { path = "parser" }
Expand Down
20 changes: 8 additions & 12 deletions src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chrono::{DateTime, Utc};
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -83,17 +83,13 @@ pub struct MCPDetails {
pub concerns: Option<Vec<(String, String)>>,
}

lazy_static! {
pub static ref TEMPLATES: Tera = {
match Tera::new("templates/*") {
Ok(t) => t,
Err(e) => {
println!("Parsing error(s): {}", e);
::std::process::exit(1);
}
}
};
}
pub static TEMPLATES: LazyLock<Tera> = LazyLock::new(|| match Tera::new("templates/*") {
Ok(t) => t,
Err(e) => {
println!("Parsing error(s): {}", e);
::std::process::exit(1);
}
});

pub fn to_human(d: DateTime<Utc>) -> String {
let d1 = chrono::Utc::now() - d;
Expand Down
10 changes: 4 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ use crate::changelogs::ChangelogFormat;
use crate::github::{GithubClient, Repository};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::sync::{Arc, RwLock};
use std::sync::{Arc, LazyLock, RwLock};
use std::time::{Duration, Instant};
use tracing as log;

pub(crate) static CONFIG_FILE_NAME: &str = "triagebot.toml";
const REFRESH_EVERY: Duration = Duration::from_secs(2 * 60); // Every two minutes

lazy_static::lazy_static! {
static ref CONFIG_CACHE:
RwLock<HashMap<String, (Result<Arc<Config>, ConfigurationError>, Instant)>> =
RwLock::new(HashMap::new());
}
static CONFIG_CACHE: LazyLock<
RwLock<HashMap<String, (Result<Arc<Config>, ConfigurationError>, Instant)>>,
> = LazyLock::new(|| RwLock::new(HashMap::new()));

// This struct maps each possible option of the triagebot.toml.
// See documentation of options at: https://forge.rust-lang.org/triagebot/pr-assignment.html#configuration
Expand Down
17 changes: 6 additions & 11 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Context as _;
use chrono::Utc;
use native_tls::{Certificate, TlsConnector};
use postgres_native_tls::MakeTlsConnector;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, LazyLock, Mutex};
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
use tokio_postgres::Client as DbClient;

Expand All @@ -14,16 +14,11 @@ pub mod rustc_commits;

const CERT_URL: &str = "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem";

lazy_static::lazy_static! {
static ref CERTIFICATE_PEMS: Vec<u8> = {
let client = reqwest::blocking::Client::new();
let resp = client
.get(CERT_URL)
.send()
.expect("failed to get RDS cert");
resp.bytes().expect("failed to get RDS cert body").to_vec()
};
}
static CERTIFICATE_PEMS: LazyLock<Vec<u8>> = LazyLock::new(|| {
let client = reqwest::blocking::Client::new();
let resp = client.get(CERT_URL).send().expect("failed to get RDS cert");
resp.bytes().expect("failed to get RDS cert body").to_vec()
});

pub struct ClientPool {
connections: Arc<Mutex<Vec<tokio_postgres::Client>>>,
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![allow(clippy::new_without_default)]

#[macro_use]
extern crate lazy_static;

use crate::github::PullRequestDetails;

use anyhow::Context;
Expand Down

0 comments on commit 22fba5d

Please # to comment.