Reduces database queries in two high-traffic endpoints by using caching and batch fetching.
Changes
routers/tools.py
Use cached tool modules when listing tools instead of re-fetching from DB per tool
models/messages.py
Added get_reactions_by_message_ids batch method for fetching reactions across multiple messages in one query
routers/channels.py
Updated get_channel_messages to batch fetch reactions instead of per-message queries
Performance Impact
GET /tools: N+1 → 1 query (or 0 if cached)
GET /channels/{id}/messages: N+1 reaction queries → 1 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/21020
**Author:** [@Classic298](https://github.com/Classic298)
**Created:** 1/28/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `more-n+1`
---
### 📝 Commits (1)
- [`4c8441e`](https://github.com/open-webui/open-webui/commit/4c8441e8880e806e0f78cbdeaa908184524f87a6) perf: eliminate N+1 queries in tools and channel messages
### 📊 Changes
**3 files changed** (+56 additions, -4 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/models/messages.py` (+50 -0)
📝 `backend/open_webui/routers/channels.py` (+5 -3)
📝 `backend/open_webui/routers/tools.py` (+1 -1)
</details>
### 📄 Description
## Summary
Reduces database queries in two high-traffic endpoints by using caching and batch fetching.
## Changes
### routers/tools.py
- Use cached tool modules when listing tools instead of re-fetching from DB per tool
### models/messages.py
- Added get_reactions_by_message_ids batch method for fetching reactions across multiple messages in one query
### routers/channels.py
- Updated get_channel_messages to batch fetch reactions instead of per-message queries
## Performance Impact
- GET /tools: N+1 → 1 query (or 0 if cached)
- GET /channels/{id}/messages: N+1 reaction queries → 1 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/21020
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:more-n+1📝 Commits (1)
4c8441eperf: eliminate N+1 queries in tools and channel messages📊 Changes
3 files changed (+56 additions, -4 deletions)
View changed files
📝
backend/open_webui/models/messages.py(+50 -0)📝
backend/open_webui/routers/channels.py(+5 -3)📝
backend/open_webui/routers/tools.py(+1 -1)📄 Description
Summary
Reduces database queries in two high-traffic endpoints by using caching and batch fetching.
Changes
routers/tools.py
models/messages.py
routers/channels.py
Performance Impact
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.