diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..a3afadb3 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - Optimizing sequential dev server checks +**Learning:** Checking the status of multiple development servers (which involves disk I/O and network port listening checks) inside a sequential for...of loop creates a significant bottleneck on the dashboard health API, as each check waits for the previous one to complete. +**Action:** Map array items to an array of Promises to initiate the I/O operations concurrently, then iterate through the array of Promises and await them sequentially to preserve order while allowing concurrent execution. diff --git a/src/pages/api/dashboard-projects-health.ts b/src/pages/api/dashboard-projects-health.ts index c9947031..c9b59e11 100644 --- a/src/pages/api/dashboard-projects-health.ts +++ b/src/pages/api/dashboard-projects-health.ts @@ -83,7 +83,7 @@ export const GET: APIRoute = async ({ locals }) => { return { pendingOrRunning: pend.length, running }; }; - for (const p of projects as ProjectRow[]) { + const projectPromises = (projects as ProjectRow[]).map(async (p) => { let dev: { ok: boolean; running?: boolean; @@ -131,13 +131,17 @@ export const GET: APIRoute = async ({ locals }) => { dev.hint = 'Erreur lecture disque'; } - payload.projects.push({ + return { id: p.id, name: p.name, swarmEnabled: Number(p.swarmEnabled) === 1, devServer: dev, tasks: countForProject(p.id), - }); + }; + }); + + for (const promise of projectPromises) { + payload.projects.push(await promise); } payload.swarm.workScheduler = await getWorkSystemStatus();