mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-08 04:16:03 -05:00
[PR #17161] [MERGED] perf: fix N+1 query issue in get_models method #24340
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/17161
Author: @sihyeonn
Created: 9/2/2025
Status: ✅ Merged
Merged: 9/3/2025
Merged by: @tjbck
Base:
dev← Head:perf/sh-models📝 Commits (1)
c0b3db3perf: fix N+1 query issue in get_models method📊 Changes
1 file changed (+9 additions, -2 deletions)
View changed files
📝
backend/open_webui/models/models.py(+9 -2)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Fixed a critical N+1 query performance issue in the
get_modelsmethod where user information was being fetched individually for each model. This optimization replaces multiple individual user queries with a single batch query, significantly improving database performance and reducing query load.This completes the N+1 query optimization across the core model listing methods (prompts, knowledge bases, and models), ensuring consistent performance improvements throughout the application.
Changed
get_modelsmethod inModelsTableclass to use batch user fetchingFixed
Additional Information
backend/open_webui/models/models.py(lines 176-196)1 + Nqueries to1 + 1queriesbase_model_id != NoneContributor 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.