mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-06-15 09:10:19 +00:00
create a CachedSchema struct
Fix the type_complexity clippy lint. Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
parent
cdc2b341b6
commit
2c89b88226
@ -428,9 +428,13 @@ impl Serialize for ChallengeSchemaWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CachedSchema {
|
||||||
|
schema: Arc<Vec<AcmeChallengeSchema>>,
|
||||||
|
cached_mtime: SystemTime,
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cached_challenge_schemas() -> Result<ChallengeSchemaWrapper, Error> {
|
fn get_cached_challenge_schemas() -> Result<ChallengeSchemaWrapper, Error> {
|
||||||
static CACHE: LazyLock<Mutex<Option<(Arc<Vec<AcmeChallengeSchema>>, SystemTime)>>> =
|
static CACHE: LazyLock<Mutex<Option<CachedSchema>>> = LazyLock::new(|| Mutex::new(None));
|
||||||
LazyLock::new(|| Mutex::new(None));
|
|
||||||
|
|
||||||
// the actual loading code
|
// the actual loading code
|
||||||
let mut last = CACHE.lock().unwrap();
|
let mut last = CACHE.lock().unwrap();
|
||||||
@ -438,10 +442,16 @@ fn get_cached_challenge_schemas() -> Result<ChallengeSchemaWrapper, Error> {
|
|||||||
let actual_mtime = fs::metadata(crate::config::acme::ACME_DNS_SCHEMA_FN)?.modified()?;
|
let actual_mtime = fs::metadata(crate::config::acme::ACME_DNS_SCHEMA_FN)?.modified()?;
|
||||||
|
|
||||||
let schema = match &*last {
|
let schema = match &*last {
|
||||||
Some((schema, cached_mtime)) if *cached_mtime >= actual_mtime => schema.clone(),
|
Some(CachedSchema {
|
||||||
|
schema,
|
||||||
|
cached_mtime,
|
||||||
|
}) if *cached_mtime >= actual_mtime => schema.clone(),
|
||||||
_ => {
|
_ => {
|
||||||
let new_schema = Arc::new(crate::config::acme::load_dns_challenge_schema()?);
|
let new_schema = Arc::new(crate::config::acme::load_dns_challenge_schema()?);
|
||||||
*last = Some((Arc::clone(&new_schema), actual_mtime));
|
*last = Some(CachedSchema {
|
||||||
|
schema: Arc::clone(&new_schema),
|
||||||
|
cached_mtime: actual_mtime,
|
||||||
|
});
|
||||||
new_schema
|
new_schema
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user