Skip to content

⚡ Bolt: Fix N+1 query in SessionManager.list_sessions#49

Draft
google-labs-jules[bot] wants to merge 1 commit intomainfrom
bolt-n-plus-one-fix-6141643900262005509
Draft

⚡ Bolt: Fix N+1 query in SessionManager.list_sessions#49
google-labs-jules[bot] wants to merge 1 commit intomainfrom
bolt-n-plus-one-fix-6141643900262005509

Conversation

@google-labs-jules
Copy link

💡 What

This change fixes an N+1 query problem in the SessionManager.list_sessions method 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 list command.

🔬 Measurement

The new test tests/test_session.py::test_list_sessions_n_plus_one_problem verifies this. Before the fix, listing 3 child sessions required 4 SELECT queries. After the fix, it only requires 2.


PR created automatically by Jules for task 6141643900262005509 started by @charles-forsyth

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.
@google-labs-jules
Copy link
Author

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

0 participants