[PR #21007] [CLOSED] perf: resolve N+1 query in prompts list access control check #41511

Closed
opened 2026-04-25 13:44:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21007
Author: @Classic298
Created: 1/28/2026
Status: Closed

Base: devHead: prompt-ac


📝 Commits (1)

  • f1958d5 fix: resolve N+1 query in prompts list access control check

📊 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 query in get_prompt_list endpoint (/prompts/list). Previously, the has_access function would query the database for user groups on each prompt in the list.

Changes

routers/prompts.py get_prompt_list endpoint:

  • Initialize groups before the condition block
  • Pre-compute user_group_ids from already-fetched groups
  • Pass user_group_ids to has_access to skip redundant DB lookups

Performance Impact

Before: N+1 queries - Groups.get_groups_by_member_id called once per prompt
After: 1 query total - reuses groups already fetched for filter construction

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/21007 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/28/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `prompt-ac` --- ### 📝 Commits (1) - [`f1958d5`](https://github.com/open-webui/open-webui/commit/f1958d53cecc2c26742f6328d5c4a36e33c5f4b5) fix: resolve N+1 query in prompts list access control check ### 📊 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 query in get_prompt_list endpoint (/prompts/list). Previously, the has_access function would query the database for user groups on each prompt in the list. ## Changes routers/prompts.py get_prompt_list endpoint: - Initialize groups before the condition block - Pre-compute user_group_ids from already-fetched groups - Pass user_group_ids to has_access to skip redundant DB lookups ## Performance Impact Before: N+1 queries - Groups.get_groups_by_member_id called once per prompt After: 1 query total - reuses groups already fetched for filter construction ### 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>
GiteaMirror added the pull-request label 2026-04-25 13:44:08 -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#41511