⚡ Bolt: Refactor admin stats to use concurrent queries - #120
Conversation
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>
|
👋 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. |
What
Refactored the
statsendpoint in the admin API (src/app/api/admin/[[...slug]]/route.ts) to execute 4 independent database aggregate queries concurrently usingPromise.all.Why
Previously, the endpoint ran 4 sequential
db.prepare(...).first()operations to gather aggregate metrics (vault_files,relay_aliases,vault_users, andstealth_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. Whiledb.batch()is usually ideal, it functions as a single transaction—if one query fails, all fail. By usingPromise.all([...first().catch(...)]), we achieve concurrent execution while retaining individual fault-tolerance for each distinct query.Impact
Measurement
Verify the improvement by profiling the
/api/admin/statsendpoint. 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