⚡ Bolt: Fix N+1 query in SessionManager.list_sessions#49
⚡ Bolt: Fix N+1 query in SessionManager.list_sessions#49google-labs-jules[bot] wants to merge 1 commit intomainfrom
Conversation
Refactors the list_sessions method to pre-fetch parent session data in a single batch query. This reduces the number of database calls from O(N) to a constant O(1) when listing sessions with parents, significantly improving performance. A new test case has been added to verify the query count reduction.
|
👋 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
This change fixes an N+1 query problem in the
SessionManager.list_sessionsmethod by pre-fetching all necessary parent session data in a single batch query.🎯 Why
Previously, the code executed a separate database query for each session with a parent inside a loop, leading to a large number of database calls and poor performance when listing many child sessions.
📊 Impact
Reduces the number of SELECT queries from N+1 to a constant 2 when listing N sessions with parents, significantly speeding up the
deep-research listcommand.🔬 Measurement
The new test
tests/test_session.py::test_list_sessions_n_plus_one_problemverifies this. Before the fix, listing 3 child sessions required 4SELECTqueries. After the fix, it only requires 2.PR created automatically by Jules for task 6141643900262005509 started by @charles-forsyth