From 733bd658d0c41337a12cc97d168f152eecf2268c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 29 May 2026 17:36:52 +0000 Subject: [PATCH] perf(api): parallelize gateway fetch with local operations Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com> --- .jules/bolt.md | 3 +++ src/pages/api/dashboard-projects-health.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..3ec857ac --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-03-24 - Optimize Gateway API Fetch Concurrency in Astro API routes +**Learning:** Initiating slow external network requests sequentially after local database queries and filesystem checks creates a bottleneck in Astro API route response times. +**Action:** When an API handler requires both external fetches and local data, start the external fetch as a Promise at the very beginning of the handler (with a dummy catch to prevent unhandled rejection crashes), execute the local operations, and then `await` the Promise at the end to parallelize the workloads. \ No newline at end of file diff --git a/src/pages/api/dashboard-projects-health.ts b/src/pages/api/dashboard-projects-health.ts index c9947031..22c15362 100644 --- a/src/pages/api/dashboard-projects-health.ts +++ b/src/pages/api/dashboard-projects-health.ts @@ -30,6 +30,10 @@ function mapSessionToRunState(raw: Record): { running: boolean /** GET — état synthétique pour la carte Projets du dashboard (poll léger). */ export const GET: APIRoute = async ({ locals }) => { const email = locals.user?.email as string | undefined; + const zimaosSessionPromise = fetchZimaOSSessionsPayload(email); + // Attach a dummy catch handler immediately to prevent UnhandledPromiseRejection + // if the fetch fails before we await it later in the final try/catch block. + zimaosSessionPromise.catch(() => {}); const payload: { projects: Array<{ @@ -150,7 +154,7 @@ export const GET: APIRoute = async ({ locals }) => { } try { - const oc = await fetchZimaOSSessionsPayload(email); + const oc = await zimaosSessionPromise; payload.swarm.zimaosOk = oc.ok; const sessions = oc.ok ? (normalizeZimaOSSessions(oc.data) as Record[])