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) {