[PR #21008] [CLOSED] perf: resolve N+1 query for group member counts #41512

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

📋 Pull Request Information

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

Base: devHead: groups-member


📝 Commits (1)

  • 5a8677c fix: resolve N+1 query for group member counts

📊 Changes

1 file changed (+28 additions, -4 deletions)

View changed files

📝 backend/open_webui/models/groups.py (+28 -4)

📄 Description

Summary

Eliminates N+1 database queries when fetching group member counts in get_groups and search_groups. Previously, each group's member count was fetched with a separate COUNT query.

Changes

models/groups.py:

  • Added get_group_member_counts_by_ids batch method using single GROUP BY query
  • Updated get_groups to use batch method
  • Updated search_groups to use batch method

Performance Impact

Before: N+1 queries (1 COUNT per group)
After: 1 query total using SQL GROUP BY
Example: 50 groups = 51 queries before, 2 queries after (main query + counts)

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/21008 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/28/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `groups-member` --- ### 📝 Commits (1) - [`5a8677c`](https://github.com/open-webui/open-webui/commit/5a8677c9abc5ec4f17a210dfe6ce329e4c9aa4ec) fix: resolve N+1 query for group member counts ### 📊 Changes **1 file changed** (+28 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/groups.py` (+28 -4) </details> ### 📄 Description ## Summary Eliminates N+1 database queries when fetching group member counts in get_groups and search_groups. Previously, each group's member count was fetched with a separate COUNT query. ## Changes models/groups.py: - Added get_group_member_counts_by_ids batch method using single GROUP BY query - Updated get_groups to use batch method - Updated search_groups to use batch method ## Performance Impact Before: N+1 queries (1 COUNT per group) After: 1 query total using SQL GROUP BY Example: 50 groups = 51 queries before, 2 queries after (main query + counts) ### 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:10 -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#41512