mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[PR #20115] [CLOSED] perf: fix N+1 query issues in user/group endpoints #41102
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20115
Author: @broskees
Created: 12/22/2025
Status: ❌ Closed
Base:
dev← Head:fix/n1-query-group-user📝 Commits (1)
de6cb7aperf: fix N+1 query issues in user/group endpoints📊 Changes
3 files changed (+177 additions, -32 deletions)
View changed files
📝
backend/open_webui/models/groups.py(+82 -6)📝
backend/open_webui/routers/scim.py(+90 -23)📝
backend/open_webui/routers/users.py(+5 -3)📄 Description
Summary
Fixes critical N+1 database query issues when listing users and groups. This dramatically improves performance for large deployments with many users and groups.
Problem
The application was making individual database queries for each user/group when loading lists:
For a deployment with 2500 users, this meant 2500+ database queries instead of just 2.
Solution
Added batch query methods that fetch all related data in a single query:
Models (
backend/open_webui/models/groups.py)get_group_ids_by_member_ids()- batch load group IDs for multiple usersget_groups_by_member_ids()- batch load full group objects for multiple usersget_member_counts_by_group_ids()- batch load member counts for multiple groupsget_groups()andsearch_groups()to use batch member countingSCIM Endpoints (
backend/open_webui/routers/scim.py)user_to_scim()to accept optional pre-fetched groupsusers_to_scim()batch function to convert multiple users efficientlygroup_to_scim()to accept optional pre-fetched membersgroups_to_scim()batch function to convert multiple groups efficiently/Usersand/Groupslist endpoints to use batch functionsAdmin Users Endpoint (
backend/open_webui/routers/users.py)get_users()to use batch group ID fetchingPerformance Impact
/Users(2500 users)/Groups(20 groups, 100 members)/users(30/page)/groupslist (50 groups)Testing
Backward Compatibility
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.