mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 03:18:23 -05:00
[PR #21000] [CLOSED] perf: resolve N+1 query in OpenAI model access control filtering #41504
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/21000
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:openai-n+1📝 Commits (1)
aaf0da7Update openai.py📊 Changes
1 file changed (+22 additions, -7 deletions)
View changed files
📝
backend/open_webui/routers/openai.py(+22 -7)📄 Description
Summary
Eliminates N+1 database query in model access control filtering for the OpenAI router. Previously, when filtering models for non-admin users, the code called get_model_by_id for each model individually.
Changes
Refactored get_filtered_models in openai.py to batch-fetch all model configurations using get_models_by_ids in a single query, then filter using a lookup dictionary.
Performance Impact
Before: N+1 queries (1 query per model)
After: 1 query total using SQL IN clause
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.