⚡ Bolt: [performance improvement] Offload dashboard KPIs counting to Astro DB SQLite aggregations#112
⚡ Bolt: [performance improvement] Offload dashboard KPIs counting to Astro DB SQLite aggregations#112bobdivx wants to merge 1 commit into
Conversation
…Astro DB SQLite aggregations
💡 What: Replaced array memory fetches (using `db.select().from(...)`) mapping to `.length` with direct SQL COUNT using `db.select({ count: count() })` alongside native SQL filtering (`where(eq(...))`, `inArray(...)`).
🎯 Why: Retrieving every record from large tables into memory just to calculate a total count is highly inefficient and risks OOM or N+1 memory bloat at scale.
📊 Impact: Massively reduces peak heap payload and network/DB transmission sizes, effectively turning an O(N) fetch into an O(1) query.
🔬 Measurement: Verified with `pnpm test` and `pnpm run check`. Ensure the `loadAstroDb()` safely returns Astro DB utilities like `count` and `inArray`.
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 replaces full memory row fetches with direct database aggregations using Drizzle ORM's count() in src/pages/api/dashboard-kpis.ts to optimize dashboard KPI retrieval, and documents this optimization in .jules/bolt.md. Feedback was provided regarding a potential regression where case-insensitive status checks in memory were replaced with case-sensitive SQL inArray queries, suggesting that strict lowercase validation should be enforced at the database insertion layer.
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.
| db.select({ count: count() }).from(AgentAppIssue).where(inArray(AgentAppIssue.status, ['open', 'in_progress'])), | ||
| db.select({ count: count() }).from(AgentDependencyRequest).where(inArray(AgentDependencyRequest.status, ['open', 'in_progress'])), |
There was a problem hiding this comment.
The original implementation used isOpenQueueStatus which performed a case-insensitive check (.toLowerCase()) on the status field. By switching to a direct SQL inArray comparison, the query is now case-sensitive in SQLite.
If there is any chance of mixed-case status values being inserted into the database (e.g., by external agents or legacy data), they will no longer be counted.
To prevent this regression, it is highly recommended to ensure strict lowercase validation at the database insertion/ingestion layer (e.g., via Zod schemas or database defaults) so that the database remains clean and the queries can run efficiently without needing case-insensitive SQL functions.
💡 What: Replaced array memory fetches (using
db.select().from(...)) mapping to.lengthwith direct SQL COUNT usingdb.select({ count: count() })alongside native SQL filtering (where(eq(...)),inArray(...)).🎯 Why: Retrieving every record from large tables into memory just to calculate a total count is highly inefficient and risks OOM or N+1 memory bloat at scale.
📊 Impact: Massively reduces peak heap payload and network/DB transmission sizes, effectively turning an O(N) fetch into an O(1) query.
🔬 Measurement: Verified with
pnpm testandpnpm run check. Ensure theloadAstroDb()safely returns Astro DB utilities likecountandinArray.PR created automatically by Jules for task 1457682352501705704 started by @bobdivx