Skip to content

⚡ Bolt: Refactor admin stats to use concurrent queries - #120

Open
secrooq wants to merge 1 commit into
mainfrom
bolt/refactor-admin-stats-concurrent-queries-6667928060599516399
Open

⚡ Bolt: Refactor admin stats to use concurrent queries#120
secrooq wants to merge 1 commit into
mainfrom
bolt/refactor-admin-stats-concurrent-queries-6667928060599516399

Conversation

@secrooq

@secrooq secrooq commented Jul 7, 2026

Copy link
Copy Markdown
Owner

What

Refactored the stats endpoint in the admin API (src/app/api/admin/[[...slug]]/route.ts) to execute 4 independent database aggregate queries concurrently using Promise.all.

Why

Previously, the endpoint ran 4 sequential db.prepare(...).first() operations to gather aggregate metrics (vault_files, relay_aliases, vault_users, and stealth_secrets). Since this is a serverless environment (Cloudflare D1), each sequential DB call incurs a discrete HTTP network roundtrip, creating an N+1 latency bottleneck. While db.batch() is usually ideal, it functions as a single transaction—if one query fails, all fail. By using Promise.all([...first().catch(...)]), we achieve concurrent execution while retaining individual fault-tolerance for each distinct query.

Impact

  • Expected to reduce the endpoint's total latency significantly by parallelizing 4 network roundtrips into 1 concurrent execution window.
  • Eliminates the N+1 DB bottleneck without sacrificing error handling.

Measurement

Verify the improvement by profiling the /api/admin/stats endpoint. Overall request time should be visibly shorter, as network wait times are parallelized instead of serialized. Test execution (unit and Playwright end-to-end) passed successfully.


PR created automatically by Jules for task 6667928060599516399 started by @secrooq

Replaced 4 sequential `db.prepare(...).first()` calls with a single `Promise.all` containing `.catch()` blocks in `src/app/api/admin/[[...slug]]/route.ts`. This removes an N+1 network latency bottleneck by making the queries run concurrently, while still preserving individual query fault tolerance (since `db.batch()` would fail entirely if a single query in the batch failed). Added `.jules/bolt.md` entry.

Co-authored-by: secrooq <81346684+secrooq@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

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

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