[PR #21020] [CLOSED] perf: eliminate N+1 queries in tools and channel messages #41522

Closed
opened 2026-04-25 13:44:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21020
Author: @Classic298
Created: 1/28/2026
Status: Closed

Base: devHead: more-n+1


📝 Commits (1)

  • 4c8441e perf: 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

  • 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>
GiteaMirror added the pull-request label 2026-04-25 13:44:26 -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#41522