mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-17 07:46:16 -05:00
[PR #14064] [CLOSED] pref/optimize_get_filtered_models prevent N+1 queries #78249
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/14064
Author: @fbluewhale
Created: 5/20/2025
Status: ❌ Closed
Base:
dev← Head:pref/optimize_get_filtered_models📝 Commits (1)
158d0adpref/optimize_get_filtered_models prevent N+1 queries📊 Changes
2 files changed (+21 additions, -10 deletions)
View changed files
📝
backend/open_webui/main.py(+14 -8)📝
backend/open_webui/models/models.py(+7 -2)📄 Description
Refactor get_filtered_models to eliminate the N+1 query problem by batch-fetching all necessary model_info objects.
Description:
This pull request refactors the get_filtered_models function to optimize performance by eliminating the N+1 query problem. By batch-fetching all necessary model_info objects in a single database query and utilizing a lookup dictionary, the number of database queries is reduced from O(N) to O(1).
Changed:
Optimized: Modified get_filtered_models to batch-fetch model_info objects required for access checks, preventing individual queries within the loop.
Performance Improvement: Enhanced the efficiency and scalability of model filtering when processing multiple models.
Fixed:
Resolved: Fixed the N+1 query issue in get_filtered_models, reducing unnecessary database load and latency.
Benefits:
Performance: Significantly reduces database queries, improving response times.
Scalability: Better handles large lists of models without degrading performance.
Maintainability: Cleaner code with separation of data fetching and processing.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.