35f9d59 fix: resolve N+1 queries in models and prompts list access control
📊 Changes
1 file changed (+6 additions, -1 deletions)
View changed files
📝backend/open_webui/routers/prompts.py (+6 -1)
📄 Description
Summary
Eliminates N+1 database queries in get_models (/models/list) and get_prompt_list (/prompts/list) endpoints. Previously, the has_access function would query the database for user groups on each item in the list.
Changes
routers/models.py
Pre-compute user_group_ids from already-fetched groups
Pass to has_access via user_group_ids parameter routers/prompts.py
Same optimization applied to prompt list endpoint
Performance Impact
Before: N+1 queries - Groups.get_groups_by_member_id called once per item
After: 1 query total - reuses groups already fetched for filter construction
The has_access function already supported the user_group_ids parameter to skip the DB lookup, it just wasn't being used in these endpoints.
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/21003
**Author:** [@Classic298](https://github.com/Classic298)
**Created:** 1/28/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `prompt-n+1`
---
### 📝 Commits (1)
- [`35f9d59`](https://github.com/open-webui/open-webui/commit/35f9d59091fe6cb934de879a16e7d1a3c2cc35ff) fix: resolve N+1 queries in models and prompts list access control
### 📊 Changes
**1 file changed** (+6 additions, -1 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/routers/prompts.py` (+6 -1)
</details>
### 📄 Description
## Summary
Eliminates N+1 database queries in get_models (/models/list) and get_prompt_list (/prompts/list) endpoints. Previously, the has_access function would query the database for user groups on each item in the list.
## Changes
**routers/models.py**
- Pre-compute user_group_ids from already-fetched groups
- Pass to has_access via user_group_ids parameter
**routers/prompts.py**
- Same optimization applied to prompt list endpoint
## Performance Impact
Before: N+1 queries - Groups.get_groups_by_member_id called once per item
After: 1 query total - reuses groups already fetched for filter construction
The has_access function already supported the user_group_ids parameter to skip the DB lookup, it just wasn't being used in these endpoints.
### 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/21003
Author: @Classic298
Created: 1/28/2026
Status: ❌ Closed
Base:
dev← Head:prompt-n+1📝 Commits (1)
35f9d59fix: resolve N+1 queries in models and prompts list access control📊 Changes
1 file changed (+6 additions, -1 deletions)
View changed files
📝
backend/open_webui/routers/prompts.py(+6 -1)📄 Description
Summary
Eliminates N+1 database queries in get_models (/models/list) and get_prompt_list (/prompts/list) endpoints. Previously, the has_access function would query the database for user groups on each item in the list.
Changes
routers/models.py
routers/prompts.py
Performance Impact
Before: N+1 queries - Groups.get_groups_by_member_id called once per item
After: 1 query total - reuses groups already fetched for filter construction
The has_access function already supported the user_group_ids parameter to skip the DB lookup, it just wasn't being used in these endpoints.
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.