⚡ Bolt: Fix N+1 query in PoolController.getPoolData by batching local keys fetch - #64
Conversation
… keys fetch - Added `getAllLocalKeys` to fetch all keys for a user in a single query. - Replaced inside-the-loop querying in `PoolController.getPoolData` with O(1) map lookups. - Prevents database connection exhaustion and reduces latency. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@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: The optimization implements a single batched database query
store.getAllLocalKeysto fetch all local key records for a user at once, replacing the N individual database queries previously executed inside thePromise.allSettledloop inPoolController.getPoolData. The retrieved keys are indexed into an in-memoryMapfor O(1) lookups during iteration.🎯 Why: The previous implementation suffered from an N+1 query problem, hitting the database once for each account. As the number of accounts grows, this pattern causes high database load and latency.
📊 Impact: Reduces the number of database queries in the
getPoolDataendpoint from N+1 (one for accounts, plus one for every account's keys) to exactly 2, regardless of how many accounts the user has.🔬 Measurement: Verify the improvement by running a trace on database queries during a request to
/api/pool. The number ofSELECT * FROM Keyqueries will now be 1, rather than scaling linearly with the number of accounts.PR created automatically by Jules for task 16955008338495311246 started by @zaydiscold