From 732ae07e2674699c68161609af61ff967ea34e58 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 31 May 2026 17:23:25 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20sequential=20dat?= =?UTF-8?q?abase=20queries=20in=20mission=20board?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com> --- .jules/bolt.md | 3 +++ src/lib/forge-mission-board.ts | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..12330e96 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-05-31 - [Optimize Sequential DB queries] +**Learning:** Sequential database queries in Astro DB (like getting projects, tasks, issues) can become a bottleneck when they are independent and can be executed concurrently. Using Promise.all with conditionally resolved promises (e.g., `Promise.resolve([])`) for optional schemas optimally groups execution without blocking. +**Action:** When working on Astro SSR endpoints and data heavy libraries like `mission-board`, proactively look for unlinked `await db.select()` queries and group them into `Promise.all()` concurrently to optimize wait times. diff --git a/src/lib/forge-mission-board.ts b/src/lib/forge-mission-board.ts index 7992719f..d9880544 100644 --- a/src/lib/forge-mission-board.ts +++ b/src/lib/forge-mission-board.ts @@ -121,18 +121,19 @@ export type MissionBoardOverview = { export async function getMissionBoardOverview(): Promise { const { db, Request, AgentAppIssue, AgentTask, TechWatchSuggestion, Project } = await loadAstroDb(); - const projects = await db.select().from(Project); + const [projects, requests, issues, tasks, techRows] = await Promise.all([ + db.select().from(Project), + db.select().from(Request).orderBy(desc(Request.id)).limit(300), + db.select().from(AgentAppIssue).orderBy(desc(AgentAppIssue.id)).limit(300), + db.select().from(AgentTask).limit(800), + TechWatchSuggestion + ? db.select().from(TechWatchSuggestion).orderBy(desc(TechWatchSuggestion.id)).limit(200) + : Promise.resolve([]), + ]); + const projectNames: Record = {}; for (const p of projects) projectNames[p.id] = String(p.name || ''); - const requests = await db.select().from(Request).orderBy(desc(Request.id)).limit(300); - const issues = await db.select().from(AgentAppIssue).orderBy(desc(AgentAppIssue.id)).limit(300); - const tasks = await db.select().from(AgentTask).limit(800); - - const techRows = TechWatchSuggestion - ? await db.select().from(TechWatchSuggestion).orderBy(desc(TechWatchSuggestion.id)).limit(200) - : []; - // Index task ↔ issue const issueTaskMap = new Map(); for (const t of tasks) {