mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-15 21:19:39 -05:00
[PR #20999] [CLOSED] perf: resolve N+1 queries in Ollama model access control filtering #64729
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/20999
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:ollama-n+1📝 Commits (3)
9189fb1fix: resolve N+1 queries in OLLAMA model access control filtering8253a1eUpdate ollama.pycbaa2feUpdate ollama.py📊 Changes
1 file changed (+38 additions, -12 deletions)
View changed files
📝
backend/open_webui/routers/ollama.py(+38 -12)📄 Description
Summary
Eliminates N+1 database queries in model access control filtering for Ollama routers. Previously, when filtering models for non-admin users, the code called get_model_by_id for each model individually, resulting in N database queries.
Changes
Refactored two locations in ollama.py:
Both now use get_models_by_ids to batch-fetch all model configurations 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
Code Quality
Used descriptive variable names for readability:
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.