⚡ Bolt: [performance improvement] Optimize sequential queries in work-diagnostic#106
⚡ Bolt: [performance improvement] Optimize sequential queries in work-diagnostic#106bobdivx wants to merge 1 commit into
Conversation
…-diagnostic 💡 What: Grouped six sequential independent database/external status queries in src/pages/api/work-diagnostic.ts into a single Promise.all. 🎯 Why: Previously, these queries were awaited sequentially, creating an N+1 style delay where the endpoint's response time was equal to the sum of all individual query latencies. By grouping them, they execute concurrently, reducing the total wait time to that of the slowest query. 📊 Impact: Expected to reduce the endpoint's database latency by roughly 50-80% depending on connection overhead, directly speeding up the diagnostic dashboard load times. 🔬 Measurement: Verified by ensuring all tests pass (pnpm test), Astro types check out (pnpm run check), and by ensuring identical endpoint return values post-refactor. Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request optimizes the work-diagnostic API route by grouping several independent database queries and system status checks into a concurrent Promise.all block, significantly reducing response latency. The reviewer suggested further optimizing the database query for AgentBudget by filtering enabled budgets directly in the database rather than in-memory, and simplifying the subsequent assignment.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const [projects, agents, budgets, costs, logs, work] = await Promise.all([ | ||
| db.select().from(Project), | ||
| db.select().from(AgentInstruction), | ||
| db.select().from(AgentBudget), |
There was a problem hiding this comment.
Instead of fetching all budgets from the database and filtering them in memory, we can filter them directly in the database query using .where(eq(AgentBudget.enabled, 1)). This reduces database payload and improves performance.
| const [projects, agents, budgets, costs, logs, work] = await Promise.all([ | |
| db.select().from(Project), | |
| db.select().from(AgentInstruction), | |
| db.select().from(AgentBudget), | |
| const [projects, agents, budgets, costs, logs, work] = await Promise.all([ | |
| db.select().from(Project), | |
| db.select().from(AgentInstruction), | |
| db.select().from(AgentBudget).where(eq(AgentBudget.enabled, 1)), |
| ]); | ||
|
|
||
| const work = await getWorkSystemStatus(); | ||
| const activeBudgets = budgets.filter((b) => b.enabled === 1); |
There was a problem hiding this comment.
💡 What: Grouped six sequential independent database/external status queries in
src/pages/api/work-diagnostic.tsinto a singlePromise.all.🎯 Why: Previously, these queries were awaited sequentially, creating an N+1 style delay where the endpoint's response time was equal to the sum of all individual query latencies. By grouping them, they execute concurrently, reducing the total wait time to that of the slowest query.
📊 Impact: Expected to reduce the endpoint's database latency by roughly 50-80% depending on connection overhead, directly speeding up the diagnostic dashboard load times.
🔬 Measurement: Verified by ensuring all tests pass (
pnpm test), Astro types check out (pnpm run check), and by ensuring identical endpoint return values post-refactor.PR created automatically by Jules for task 4278117521475171296 started by @bobdivx