[PR #21000] [CLOSED] perf: resolve N+1 query in OpenAI model access control filtering #25874

Closed
opened 2026-04-20 06:10:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: devHead: openai-n+1


📝 Commits (1)

📊 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.

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/21000 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/28/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `openai-n+1` --- ### 📝 Commits (1) - [`aaf0da7`](https://github.com/open-webui/open-webui/commit/aaf0da7faf4f0bfc2bd0b872efc1e736ba862e2d) Update openai.py ### 📊 Changes **1 file changed** (+22 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/openai.py` (+22 -7) </details> ### 📄 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)](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-20 06:10:32 -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#25874