Eliminates N+1 database queries in two models router endpoints.
Changes
GET /models/list (get_models)
Pre-compute user_group_ids from already-fetched groups
Pass to has_access to avoid re-querying groups per model POST /models/import (import_models)
Batch-fetch all existing models using get_models_by_ids before the import loop
Use dict lookup instead of per-model database query
Performance Impact
get_models: N+1 → 1 query (reuses groups already fetched for filtering)
import_models: N+1 → 1 query (single batch fetch with 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/21004
**Author:** [@Classic298](https://github.com/Classic298)
**Created:** 1/28/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `model-router-list`
---
### 📝 Commits (2)
- [`e1ecb0d`](https://github.com/open-webui/open-webui/commit/e1ecb0dd5346f3cf424e15c5cd3121ec18280045) fix: resolve N+1 queries in models router (list and import)
- [`92fe87b`](https://github.com/open-webui/open-webui/commit/92fe87b296fb08d6cc0d90f9ce5877a61c21151f) Update models.py
### 📊 Changes
**1 file changed** (+9 additions, -2 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/routers/models.py` (+9 -2)
</details>
### 📄 Description
## Summary
Eliminates N+1 database queries in two models router endpoints.
## Changes
**GET /models/list (get_models)**
- Pre-compute user_group_ids from already-fetched groups
- Pass to has_access to avoid re-querying groups per model
**POST /models/import (import_models)**
- Batch-fetch all existing models using get_models_by_ids before the import loop
- Use dict lookup instead of per-model database query
## Performance Impact
get_models: N+1 → 1 query (reuses groups already fetched for filtering)
import_models: N+1 → 1 query (single batch fetch with 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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21004
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:model-router-list📝 Commits (2)
e1ecb0dfix: resolve N+1 queries in models router (list and import)92fe87bUpdate models.py📊 Changes
1 file changed (+9 additions, -2 deletions)
View changed files
📝
backend/open_webui/routers/models.py(+9 -2)📄 Description
Summary
Eliminates N+1 database queries in two models router endpoints.
Changes
GET /models/list (get_models)
POST /models/import (import_models)
Performance Impact
get_models: N+1 → 1 query (reuses groups already fetched for filtering)
import_models: N+1 → 1 query (single batch fetch with 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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.