Skip to content

Commit 8d0b047

Browse files
committed
Only parse environment variables and CLI arguments on startup
Environment variables and CLI arguments can only be changed with a process restart, so there is no point in parsing them every time we hot reload our configuration. Instead, we can put the parsed configuration in a `LazyLock` which will be initialized when we first parse configuration on startup and then re-used when we hot reload.
1 parent b4c7d6c commit 8d0b047

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fact/src/config/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
net::SocketAddr,
44
path::{Path, PathBuf},
55
str::FromStr,
6+
sync::LazyLock,
67
};
78

89
use anyhow::{bail, Context};
@@ -66,8 +67,8 @@ impl FactConfig {
6667
)?;
6768

6869
// Once file configuration is handled, apply CLI arguments
69-
let args = FactCli::try_parse()?;
70-
config.update(&args.to_config());
70+
static CLI_ARGS: LazyLock<FactConfig> = LazyLock::new(|| FactCli::parse().to_config());
71+
config.update(&CLI_ARGS);
7172

7273
Ok(config)
7374
}

0 commit comments

Comments
 (0)