[PR #14064] [CLOSED] pref/optimize_get_filtered_models prevent N+1 queries #78249

Closed
opened 2026-05-13 11:51:59 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/14064
Author: @fbluewhale
Created: 5/20/2025
Status: Closed

Base: devHead: pref/optimize_get_filtered_models


📝 Commits (1)

  • 158d0ad pref/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.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/14064 **Author:** [@fbluewhale](https://github.com/fbluewhale) **Created:** 5/20/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `pref/optimize_get_filtered_models` --- ### 📝 Commits (1) - [`158d0ad`](https://github.com/open-webui/open-webui/commit/158d0adb921a18bf078982d227f5f92d363db417) pref/optimize_get_filtered_models prevent N+1 queries ### 📊 Changes **2 files changed** (+21 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/main.py` (+14 -8) 📝 `backend/open_webui/models/models.py` (+7 -2) </details> ### 📄 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. --- <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-05-13 11:51:59 -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#78249