From cb7c83f67024c3af4cb127f0717838d39e74dc66 Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Tue, 9 Dec 2025 00:03:47 -0500 Subject: [PATCH] fix: add simple 30s cache to /healthcheck --- .../src/modules/core/ServerHealthService.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/backend/src/modules/core/ServerHealthService.js b/src/backend/src/modules/core/ServerHealthService.js index 0e1717fe..775c5451 100644 --- a/src/backend/src/modules/core/ServerHealthService.js +++ b/src/backend/src/modules/core/ServerHealthService.js @@ -213,17 +213,36 @@ class ServerHealthService extends BaseService { /** * Retrieves the current health status of the server. + * Results are cached for 30 seconds to reduce computation overhead. * * @returns {Object} An object containing: * - `ok` {boolean}: Indicates if all health checks passed. * - `failed` {Array}: An array of names of failed health checks, if any. */ - get_status () { + async get_status () { + const cache_key = 'server-health:status'; + + // Check cache first + if ( globalThis.kv ) { + const cached = globalThis.kv.get(cache_key); + if ( cached ) { + return cached; + } + } + + // Compute status const failures = this.failures_.map(v => v.name); - return { + const status = { ok: failures.length === 0, ...(failures.length ? { failed: failures } : {}), }; + + // Cache with 30 second TTL + if ( globalThis.kv ) { + globalThis.kv.set(cache_key, status, { EX: 30 }); + } + + return status; } }