From c343b52b5755fec17ff6e270fc9824c6eeddc050 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Tue, 12 May 2026 15:12:59 +0200 Subject: [PATCH] Improve cache handling with on-demand cache warm-up and increase cURL timeout - Implement on-demand warming of manual and automatic flags cache in `invoice_period_flag_service` to handle cache misses effectively. - Extend cURL timeout in `economic_endpoint_t` for improved reliability in network requests. --- .../classes/invoice_period_flag_service.php | 35 +++++++++++++++---- .../nginx/app/traits/economic_endpoint_t.php | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/services/nginx/app/classes/invoice_period_flag_service.php b/services/nginx/app/classes/invoice_period_flag_service.php index c6a2a329..9625d80b 100644 --- a/services/nginx/app/classes/invoice_period_flag_service.php +++ b/services/nginx/app/classes/invoice_period_flag_service.php @@ -384,11 +384,20 @@ class invoice_period_flag_service try { $flags = (new redis())->get_invoice_period_manual_flags(); } catch (Throwable) { - return []; + $flags = null; } if (!is_array($flags)) { - return []; + // Cache miss — warm on demand and re-fetch + $this->warmManualFlagsCache(); + try { + $flags = (new redis())->get_invoice_period_manual_flags(); + } catch (Throwable) { + return []; + } + if (!is_array($flags)) { + return []; + } } return array_values(array_filter($flags, static function ($flag): bool { @@ -516,11 +525,20 @@ class invoice_period_flag_service try { $flags = (new redis())->get_invoice_period_automatic_flags($dateFrom, $dateTo); } catch (Throwable) { - return []; + $flags = null; } if (!is_array($flags)) { - return []; + // Cache miss — warm on demand and re-fetch + $this->warmAutomaticFlagsForPeriod($dateFrom, $dateTo); + try { + $flags = (new redis())->get_invoice_period_automatic_flags($dateFrom, $dateTo); + } catch (Throwable) { + return []; + } + if (!is_array($flags)) { + return []; + } } if ($onlyCustomerNumbers === null) { @@ -592,11 +610,16 @@ class invoice_period_flag_service try { $rows = (new redis())->get_invoice_period_order_item_rows($dateFrom, $dateTo); } catch (Throwable) { - return []; + $rows = null; } if (!is_array($rows)) { - return []; + // Cache miss — fetch from DB and cache for next request + $rows = $this->fetchOrderItemRowsFromDb($dateFrom, $dateTo); + try { + (new redis())->cache_invoice_period_order_item_rows($dateFrom, $dateTo, $rows); + } catch (Throwable) { + } } $this->seedOrderItemsPreviewCacheFromRows($rows); diff --git a/services/nginx/app/traits/economic_endpoint_t.php b/services/nginx/app/traits/economic_endpoint_t.php index a8ca6394..2a2926e3 100644 --- a/services/nginx/app/traits/economic_endpoint_t.php +++ b/services/nginx/app/traits/economic_endpoint_t.php @@ -148,7 +148,7 @@ trait economic_endpoint_t //CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_CONNECTTIMEOUT => 3, - CURLOPT_TIMEOUT => 10, + CURLOPT_TIMEOUT => 30, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS, CURLOPT_CUSTOMREQUEST => $method,