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 @@
## 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.
19 changes: 10 additions & 9 deletions src/lib/forge-mission-board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,19 @@ export type MissionBoardOverview = {
export async function getMissionBoardOverview(): Promise<MissionBoardOverview> {
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<number, string> = {};
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<number, { id: number; status: string }>();
for (const t of tasks) {
Expand Down