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

server: Replace usage of once_cell with equivalent from std #1820

Merged
merged 1 commit into from
Mar 24, 2025
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
1 change: 0 additions & 1 deletion server/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 server/svix-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ serde_path_to_error = "0.1.7"
num_enum = "0.7.2"
enum_dispatch = "0.3.8"
regex = "1.5.5"
once_cell = "1.18.0"
figment = { version = "0.10", features = ["toml", "env", "test"] }
tracing = "0.1.35"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
Expand Down
4 changes: 2 additions & 2 deletions server/svix-server/src/core/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use std::{
collections::{HashMap, HashSet},
ops::Deref,
sync::LazyLock,
};

use chrono::{DateTime, Utc};
use num_enum::{IntoPrimitive, TryFromPrimitive};
use once_cell::sync::Lazy;
use rand::Rng;
use regex::Regex;
use schemars::JsonSchema;
Expand Down Expand Up @@ -229,7 +229,7 @@ pub trait BaseId: Deref<Target = String> {

fn validate_limited_str(s: &str) -> Result<(), ValidationErrors> {
const MAX_LENGTH: usize = 256;
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9\-_.]+$").unwrap());
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[a-zA-Z0-9\-_.]+$").unwrap());
let mut errors = ValidationErrors::new();
if s.is_empty() {
errors.add(
Expand Down
10 changes: 6 additions & 4 deletions server/svix-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use std::{
borrow::Cow,
sync::atomic::{AtomicBool, Ordering},
sync::{
atomic::{AtomicBool, Ordering},
LazyLock,
},
time::Duration,
};

use aide::axum::ApiRouter;
use cfg::ConfigurationInner;
use once_cell::sync::Lazy;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{metrics::SdkMeterProvider, runtime::Tokio};
use queue::TaskQueueProducer;
Expand Down Expand Up @@ -57,8 +59,8 @@ const CRATE_NAME: &str = env!("CARGO_CRATE_NAME");

pub static SHUTTING_DOWN: AtomicBool = AtomicBool::new(false);

pub static INSTANCE_ID: Lazy<String> =
Lazy::new(|| hex::encode(KsuidMs::new(None, None).to_string()));
pub static INSTANCE_ID: LazyLock<String> =
LazyLock::new(|| hex::encode(KsuidMs::new(None, None).to_string()));

async fn graceful_shutdown_handler() {
let ctrl_c = async {
Expand Down
12 changes: 7 additions & 5 deletions server/svix-server/src/v1/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
collections::HashSet,
error::Error as StdError,
ops::Deref,
sync::LazyLock,
time::{SystemTime, UNIX_EPOCH},
};

Expand All @@ -25,7 +26,6 @@ use axum::{
};
use chrono::{DateTime, Utc};
use http::{request::Parts, Request, StatusCode};
use once_cell::sync::Lazy;
use regex::Regex;
use schemars::JsonSchema;
use sea_orm::{ColumnTrait, QueryFilter, QueryOrder, QuerySelect};
Expand All @@ -49,11 +49,13 @@ const fn default_limit() -> PaginationLimit {

const PAGINATION_LIMIT_CAP_HARD: bool = true;
const PAGINATION_LIMIT_CAP_LIMIT: u64 = 250;
static PAGINATION_LIMIT_ERROR: Lazy<String> =
Lazy::new(|| format!("Given limit must not exceed {PAGINATION_LIMIT_CAP_LIMIT}"));
static PAGINATION_LIMIT_ERROR: LazyLock<String> =
LazyLock::new(|| format!("Given limit must not exceed {PAGINATION_LIMIT_CAP_LIMIT}"));

static FUTURE_QUERY_LIMIT: Lazy<chrono::Duration> = Lazy::new(|| chrono::Duration::hours(1));
static LIMITED_QUERY_DURATION: Lazy<chrono::Duration> = Lazy::new(|| chrono::Duration::days(90));
static FUTURE_QUERY_LIMIT: LazyLock<chrono::Duration> =
LazyLock::new(|| chrono::Duration::hours(1));
static LIMITED_QUERY_DURATION: LazyLock<chrono::Duration> =
LazyLock::new(|| chrono::Duration::days(90));

#[derive(Debug, Deserialize, Validate, JsonSchema)]
pub struct PaginationDescending<T: Validate + JsonSchema> {
Expand Down
5 changes: 2 additions & 3 deletions server/svix-server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
collections::HashMap,
sync::{
atomic::{AtomicU64, AtomicUsize, Ordering},
Arc,
Arc, LazyLock,
},
time::Duration,
};
Expand All @@ -14,7 +14,6 @@ use axum::body::HttpBody as _;
use chrono::Utc;
use futures::future;
use http::{HeaderValue, StatusCode, Version};
use once_cell::sync::Lazy;
use rand::Rng;
use sea_orm::{
prelude::DateTimeUtc, ActiveModelBehavior, ActiveModelTrait, ColumnTrait, DatabaseConnection,
Expand Down Expand Up @@ -912,7 +911,7 @@ async fn process_queue_task_inner(
Ok(())
}

pub static LAST_QUEUE_POLL: Lazy<AtomicU64> = Lazy::new(|| get_unix_timestamp().into());
pub static LAST_QUEUE_POLL: LazyLock<AtomicU64> = LazyLock::new(|| get_unix_timestamp().into());

async fn update_last_poll_time() {
LAST_QUEUE_POLL.swap(get_unix_timestamp(), Ordering::Relaxed);
Expand Down