From 18bf93a8018183f9e295ee18d20234fd4f223e40 Mon Sep 17 00:00:00 2001 From: Dusan Vojacek Date: Fri, 12 Jun 2026 14:46:51 +0200 Subject: [PATCH] =?UTF-8?q?HOTFIX=202/2:=20delta=20profil=20=E2=80=94=20?= =?UTF-8?q?=C4=8Dten=C3=A1=C5=99=20NIKDY=20nepo=C4=8D=C3=ADt=C3=A1,=20jen?= =?UTF-8?q?=20=C4=8Dte=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Postřeh uživatele odhalil druhou půlku problému: _cached getter měl max_age 30 min s INLINE fallbackem na plný 44s přepočet — dosud to maskoval 15min refresh; po throttlu refresh jednou za 6 h by KAŽDÉ čtení po vystárnutí cache (plan/current, canonical sloty plánovače) spouštělo 44 s. Čtenář teď vrací cache bez ohledu na stáří; počítá výhradně refresh (throttle 6 h + denní catch-up). Inline jen first-run/analytická okna. Co-Authored-By: Claude Opus 4.8 (1M context) --- db/routines/R__018_fn_pv_delta_profile_cache.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/db/routines/R__018_fn_pv_delta_profile_cache.sql b/db/routines/R__018_fn_pv_delta_profile_cache.sql index 6167269..7cd4295 100644 --- a/db/routines/R__018_fn_pv_delta_profile_cache.sql +++ b/db/routines/R__018_fn_pv_delta_profile_cache.sql @@ -81,14 +81,17 @@ begin from ems.site_pv_forecast_calibration c where c.site_id = p_site_id; + -- ČTENÁŘ NIKDY NEPOČÍTÁ (přepočet = 44 s/site na prod!). Vrací cache bez + -- ohledu na stáří (přepočet řídí výhradně fn_refresh_… — throttle 6 h + -- z fill_forecast_accuracy ticku + denní catch-up). p_max_age ponechán + -- v signatuře kvůli kompatibilitě volajících, ignoruje se. if v_cached is not null - and v_cached_at is not null - and v_cached_at >= now() - p_max_age - and p_data_from >= (now() - interval '120 days') + and p_data_from >= (now() - interval '121 days') and p_data_to <= now() + interval '5 minutes' then return v_cached; end if; + -- jen first-run (cache NULL) nebo nestandardní analytické okno: return ems.fn_pv_forecast_delta_profile( p_site_id, p_data_from, @@ -103,4 +106,4 @@ end; $fn$; comment on function ems.fn_pv_forecast_delta_profile_cached is - 'Delta profil z cache (max 30 min) nebo přepočet; pro canonical PV a /plan/current.'; + 'Delta profil VŽDY z cache (stáří řídí refresh job, ne čtenář — přepočet 44 s/site); inline přepočet jen first-run / nestandardní okno.';