From 8c3ce9ae35f0a7a7de47e4cbac2ad71de9897d2d Mon Sep 17 00:00:00 2001 From: Stefan Date: Fri, 4 Jul 2025 02:33:55 +0200 Subject: [PATCH] fix: timezone caching --- core/expression/src/vm/date/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/expression/src/vm/date/mod.rs b/core/expression/src/vm/date/mod.rs index 88a72c24..99355b75 100644 --- a/core/expression/src/vm/date/mod.rs +++ b/core/expression/src/vm/date/mod.rs @@ -185,12 +185,17 @@ mod helper { use rust_decimal::prelude::ToPrimitive; use std::ops::{Add, Deref}; use std::str::FromStr; + use std::sync::OnceLock; fn tz() -> Tz { - iana_time_zone::get_timezone() - .ok() - .and_then(|tz| Tz::from_str(&tz).ok()) - .unwrap_or_else(|| Tz::UTC) + static CACHED_TZ: OnceLock = OnceLock::new(); + + *CACHED_TZ.get_or_init(|| { + iana_time_zone::get_timezone() + .ok() + .and_then(|tz| Tz::from_str(&tz).ok()) + .unwrap_or_else(|| Tz::UTC) + }) } pub fn now() -> DateTime {