Skip to content

⚡ Bolt: Optimize Knowledgebase Fetch#80

Open
nkissick-del wants to merge 1 commit intomainfrom
bolt-optimize-kb-fetch-8961361476201916237
Open

⚡ Bolt: Optimize Knowledgebase Fetch#80
nkissick-del wants to merge 1 commit intomainfrom
bolt-optimize-kb-fetch-8961361476201916237

Conversation

@nkissick-del
Copy link
Copy Markdown
Owner

⚡ Bolt: Optimize Knowledgebase Fetch

💡 What:
Replaced the manual offset/limit loop in KnowledgebaseService.get_all_kb_by_tenant_ids with a single query execution. Also fixed a bug where order_by was ignored.

🎯 Why:
The original implementation used a while loop with offset and limit to fetch all records. This causes N/batch_size queries, and each query gets slower due to OFFSET scanning (O(N^2) total work). It also had a bug where kbs.order_by(...) was called without assignment, so the results were likely unordered.

📊 Impact:

  • Reduces database queries from N/50 to 1.
  • Eliminates the O(N^2) scanning overhead of deep pagination.
  • Ensures results are correctly ordered by creation time.

🔬 Measurement:
Verified with a unit test (test/unit_test/services/test_kb_perf.py) which mocked the DB and asserted that offset and limit are no longer called, and that dicts() is called on the ordered query object. The test was deleted after verification.


PR created automatically by Jules for task 8961361476201916237 started by @nkissick-del

- Replaced inefficient O(N^2) manual offset pagination loop with a single query execution.
- Fixed a bug where `order_by` was ignored because the result was not assigned.
- This improves performance for fetching knowledge bases, especially when the count is large.

Co-authored-by: nkissick-del <236767245+nkissick-del@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 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