Skip to content

⚡ Bolt: Optimize ZimaOS API calls to prevent blocking database queries#109

Open
bobdivx wants to merge 1 commit into
devfrom
bolt/optimize-dashboard-api-concurrency-16260373952113755961
Open

⚡ Bolt: Optimize ZimaOS API calls to prevent blocking database queries#109
bobdivx wants to merge 1 commit into
devfrom
bolt/optimize-dashboard-api-concurrency-16260373952113755961

Conversation

@bobdivx

@bobdivx bobdivx commented Jun 11, 2026

Copy link
Copy Markdown
Owner

💡 What: Hoisted the fetchZimaOSSessionsPayload slow network call to execute concurrently with Astro database queries in both dashboard-projects-health.ts and dashboard-kpis.ts. The Promise is immediately detached with a .catch(() => {}) handler to prevent unhandled rejection crashes if it fails before it's awaited later in the route. Also grouped sequential db selects with Promise.all.

🎯 Why: These gateway calls could take hundreds of milliseconds and were previously blocking the execution of entirely independent database queries, slowing down the overall SSR response time.

📊 Impact: Reduces total request time from (db_time + network_time) to max(db_time, network_time).

🔬 Measurement: Verify by loading the dashboard and comparing the TTI/load times of the KPI cards and Projects Health views, or by injecting an artificial delay into the fetchZimaOSSessionsPayload mock during testing to see that DB queries continue unblocked.


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

💡 What: Hoisted the `fetchZimaOSSessionsPayload` slow network call to execute concurrently with Astro database queries in both `dashboard-projects-health.ts` and `dashboard-kpis.ts`. The Promise is immediately detached with a `.catch(() => {})` handler to prevent unhandled rejection crashes if it fails before it's awaited later in the route. Also grouped sequential db selects with `Promise.all`.

🎯 Why: These gateway calls could take hundreds of milliseconds and were previously blocking the execution of entirely independent database queries, slowing down the overall SSR response time.

📊 Impact: Reduces total request time from `(db_time + network_time)` to `max(db_time, network_time)`.

🔬 Measurement: Verify by loading the dashboard and comparing the TTI/load times of the KPI cards and Projects Health views, or by injecting an artificial delay into the `fetchZimaOSSessionsPayload` mock during testing to see that DB queries continue unblocked.

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 11, 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 11, 2026 5:37pm

@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 Astro API routes in dashboard-kpis.ts and dashboard-projects-health.ts by initiating slow external network calls early and concurrently with database queries. Feedback on both files highlights that simply chaining .catch(() => {}) to the initial promise will still cause the subsequent await statement to throw an exception upon rejection. The reviewer suggests handling the rejection directly within the .catch handler by returning a fallback payload object, ensuring the promise always resolves safely to a valid structure.

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 +30 to +31
const zimaosPromise = fetchZimaOSSessionsPayload(undefined);
zimaosPromise.catch(() => {}); // prevent unhandled rejection if failed before awaited

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 calling .catch(() => {}) on the promise and then awaiting the original promise (which will still throw on rejection), it is cleaner and safer to handle the rejection by returning a fallback ZimaOSSessionsPayloadResult object directly in the .catch handler. This avoids throwing/catching exceptions during the await phase and ensures zimaosPromise always resolves to a valid payload structure.

  const zimaosPromise = fetchZimaOSSessionsPayload(undefined).catch((err) => ({
    ok: false,
    status: 500,
    data: null,
    error: err instanceof Error ? err.message : String(err),
    attempts: [],
  }));

Comment on lines +40 to +41
const zimaosPromise = fetchZimaOSSessionsPayload(email);
zimaosPromise.catch(() => {}); // prevent unhandled rejection if failed before awaited

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

Similar to the KPIs endpoint, handling the promise rejection by returning a fallback ZimaOSSessionsPayloadResult object directly in the .catch handler is cleaner and safer. This avoids throwing/catching exceptions during the await phase and ensures zimaosPromise always resolves to a valid payload structure.

  const zimaosPromise = fetchZimaOSSessionsPayload(email).catch((err) => ({
    ok: false,
    status: 500,
    data: null,
    error: err instanceof Error ? err.message : String(err),
    attempts: [],
  }));

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