[PR #21018] [MERGED] perf: batch fetch filter functions to eliminate N+1 queries #113201

Closed
opened 2026-05-18 13:31:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21018
Author: @Classic298
Created: 1/28/2026
Status: Merged
Merged: 1/29/2026
Merged by: @tjbck

Base: devHead: function-perf


📝 Commits (1)

  • 9d4f502 perf: batch fetch filter functions to eliminate N+1 queries

📊 Changes

3 files changed (+24 additions, -12 deletions)

View changed files

📝 backend/open_webui/models/functions.py (+20 -0)
📝 backend/open_webui/utils/chat.py (+2 -6)
📝 backend/open_webui/utils/middleware.py (+2 -6)

📄 Description

Summary

Adds a batch method to fetch multiple functions by ID in a single database query, eliminating N+1 query patterns in filter function loading.

Changes

  • Added get_functions_by_ids batch method in FunctionsTable
  • Updated chat_completed in utils/chat.py to use batch fetch
  • Updated process_chat_payload in utils/middleware.py to use batch fetch

Performance Impact

For a request with N filter functions:

  • Before: N separate database queries
  • After: 1 database query

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/21018 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/28/2026 **Status:** ✅ Merged **Merged:** 1/29/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `function-perf` --- ### 📝 Commits (1) - [`9d4f502`](https://github.com/open-webui/open-webui/commit/9d4f50235b49e27fa4c1484b4c57cf17578f4756) perf: batch fetch filter functions to eliminate N+1 queries ### 📊 Changes **3 files changed** (+24 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/functions.py` (+20 -0) 📝 `backend/open_webui/utils/chat.py` (+2 -6) 📝 `backend/open_webui/utils/middleware.py` (+2 -6) </details> ### 📄 Description ## Summary Adds a batch method to fetch multiple functions by ID in a single database query, eliminating N+1 query patterns in filter function loading. ## Changes - Added get_functions_by_ids batch method in FunctionsTable - Updated chat_completed in utils/chat.py to use batch fetch - Updated process_chat_payload in utils/middleware.py to use batch fetch ## Performance Impact For a request with N filter functions: - Before: N separate database queries - After: 1 database query ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-18 13:31:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#113201