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>
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/21008
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:groups-member📝 Commits (1)
5a8677cfix: 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:
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.