From 385e0b25b11b66023aedac4b960c764b5caed36e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 24 May 2026 17:36:03 +0000 Subject: [PATCH] perf(api): run agent budget db queries concurrently - Grouped sequential `db.select()` queries in `src/pages/api/agent-budget.ts` inside a single `Promise.all()`. - Created `.jules/bolt.md` to journal the codebase-specific learning about optimizing independent query lookups via concurrency. Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ src/pages/api/agent-budget.ts | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..40a34110 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,4 @@ +## 2025-02-20 - [Performance] Optimize independent backend sequential queries + +**Learning:** When retrieving data from Astro DB/Drizzle ORM using multiple `await db.select().from(Table)` queries in an API endpoint, doing so sequentially creates unnecessary sequential I/O bottleneck wait time. +**Action:** Identify independent queries in data retrieval endpoints and group them using `await Promise.all([db.select()..., db.select()...])` to execute them concurrently, reducing total wait time to the longest single query without sacrificing code readability. diff --git a/src/pages/api/agent-budget.ts b/src/pages/api/agent-budget.ts index a135f158..3f66b5a8 100644 --- a/src/pages/api/agent-budget.ts +++ b/src/pages/api/agent-budget.ts @@ -17,9 +17,12 @@ export async function GET({ url }: { url: URL }) { const agentId = url.searchParams.get('agentId'); // Récupérer tous les budgets (avec infos agents) - const budgets = await db.select().from(AgentBudget); - const allEvents = await db.select().from(CostEvent); - const instructions = await db.select().from(AgentInstruction); + // ⚡ Bolt: Concurrent query execution to avoid sequential I/O bottlenecks + const [budgets, allEvents, instructions] = await Promise.all([ + db.select().from(AgentBudget), + db.select().from(CostEvent), + db.select().from(AgentInstruction), + ]); // Map agentId → model name const agentModels: Record = {};