Skip to content

⚡ Bolt: [performance improvement] Optimize sequential queries in work-diagnostic#106

Open
bobdivx wants to merge 1 commit into
devfrom
bolt-optimize-work-diagnostic-4278117521475171296
Open

⚡ Bolt: [performance improvement] Optimize sequential queries in work-diagnostic#106
bobdivx wants to merge 1 commit into
devfrom
bolt-optimize-work-diagnostic-4278117521475171296

Conversation

@bobdivx

@bobdivx bobdivx commented Jun 10, 2026

Copy link
Copy Markdown
Owner

💡 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.


PR created automatically by Jules for task 4278117521475171296 started by @bobdivx

…-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>
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
forge Ready Ready Preview, Comment Jun 10, 2026 5:22pm

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +21 to +24
const [projects, agents, budgets, costs, logs, work] = await Promise.all([
db.select().from(Project),
db.select().from(AgentInstruction),
db.select().from(AgentBudget),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since the budgets are now filtered directly in the database query, we can simplify this line by assigning budgets directly to activeBudgets without the in-memory .filter() call.

Suggested change
const activeBudgets = budgets.filter((b) => b.enabled === 1);
const activeBudgets = budgets;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant