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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 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:
dev← Head:function-perf📝 Commits (1)
9d4f502perf: 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
Performance Impact
For a request with N filter functions:
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.