⚡ Bolt: Optimize ZimaOS API calls to prevent blocking database queries#109
⚡ Bolt: Optimize ZimaOS API calls to prevent blocking database queries#109bobdivx wants to merge 1 commit into
Conversation
💡 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>
|
👋 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 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.
| const zimaosPromise = fetchZimaOSSessionsPayload(undefined); | ||
| zimaosPromise.catch(() => {}); // prevent unhandled rejection if failed before awaited |
There was a problem hiding this comment.
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: [],
}));| const zimaosPromise = fetchZimaOSSessionsPayload(email); | ||
| zimaosPromise.catch(() => {}); // prevent unhandled rejection if failed before awaited |
There was a problem hiding this comment.
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: [],
}));
💡 What: Hoisted the
fetchZimaOSSessionsPayloadslow network call to execute concurrently with Astro database queries in bothdashboard-projects-health.tsanddashboard-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 withPromise.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)tomax(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
fetchZimaOSSessionsPayloadmock during testing to see that DB queries continue unblocked.PR created automatically by Jules for task 16260373952113755961 started by @bobdivx