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 = {};