mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[PR #21002] [CLOSED] perf: resolve N+1 query in models list access control check #25876
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/21002
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:group-check-n+1📝 Commits (1)
0a383cafix: resolve N+1 query in models list access control check📊 Changes
1 file changed (+6 additions, -1 deletions)
View changed files
📝
backend/open_webui/routers/models.py(+6 -1)📄 Description
Summary
Eliminates N+1 database query in the get_models endpoint (/list). Previously, the has_access function would query the database for user groups on each model in the list.
Changes
Pre-compute user_group_ids once from the already-fetched groups (which were being fetched anyway for the filter), then pass to has_access via the user_group_ids parameter.
Performance Impact
Before: N+1 queries - Groups.get_groups_by_member_id called once per model
After: 1 query total - reuses the groups already fetched for filter construction
The has_access function already supported the user_group_ids parameter to skip the DB lookup, it just wasn't being used here.
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.