Skip to content

⚡ Bolt: [performance improvement] Offload dashboard KPIs counting to Astro DB SQLite aggregations#112

Open
bobdivx wants to merge 1 commit into
devfrom
jules-1457682352501705704-f58d7c0a
Open

⚡ Bolt: [performance improvement] Offload dashboard KPIs counting to Astro DB SQLite aggregations#112
bobdivx wants to merge 1 commit into
devfrom
jules-1457682352501705704-f58d7c0a

Conversation

@bobdivx

@bobdivx bobdivx commented Jun 12, 2026

Copy link
Copy Markdown
Owner

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


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

…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>
@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 12, 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 12, 2026 5:36pm

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

Comment on lines +50 to +51
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'])),

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

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.

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