Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 7 additions & 3 deletions src/pages/api/dashboard-projects-health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down