diff --git a/src/main.rs b/src/main.rs index bdcfa6e..bcd321f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,30 @@ macro_rules! get_locations { }; } + +pub static FLOW_INFO: OnceCell> = OnceCell::const_new(); + +#[macro_export] +macro_rules! get_flows { + () => { + if let Some(client) = $crate::FLOW_INFO.get() { + client + } else { + let mut flows: $crate::json_store::JSONStore<$crate::flow::FlowInfo> = + $crate::JSONStore::new("./flows"); + + let flow_keys: Vec<_> = flows.keys().cloned().collect(); + for flow_key in flow_keys { + let flow = flows.get_mut(&flow_key).unwrap(); + flow.id = flow_key.clone(); + } + + $crate::FLOW_INFO.set(flows).unwrap(); + $crate::FLOW_INFO.get().unwrap() + } + }; +} + // ░░░░░░░░░░▀▀▀██████▄▄▄░░░░░░░░░░ // ░░░░░░░░░░░░░░░░░▀▀▀████▄░░░░░░░ // ░░░░░░░░░░▄███████▀░░░▀███▄░░░░░ @@ -113,7 +137,7 @@ async fn rocket() -> _ { let config = config::get_config(); let itemdb = get_itemdb!().clone(); let locations = get_locations!().clone(); - let flows: JSONStore = JSONStore::new("./flows"); + let flows = get_flows!().clone(); integrity::verify_integrity(&config, &flows, &locations, &itemdb).await; rocket::build()