[PR #21616] [CLOSED] perf: Eliminate N+1 access grant queries in prompts listing #49212

Closed
opened 2026-04-30 01:32:24 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21616
Author: @Classic298
Created: 2/19/2026
Status: Closed

Base: devHead: perf-prompt-list


📝 Commits (1)

  • ae9e9ee Eliminate N+1 access grant queries in prompts listing

📊 Changes

2 files changed (+68 additions, -11 deletions)

View changed files

📝 backend/open_webui/models/access_grants.py (+30 -0)
📝 backend/open_webui/models/prompts.py (+38 -11)

📄 Description

The prompts listing endpoints were calling _get_access_grants() per
prompt (N+1 queries) via _to_prompt_model(). Additionally,
get_prompts_by_user_id() called has_access() per prompt for filtering
(another N+1). Now:

  • get_prompts() batch-fetches all access grants in one query via new
    get_grants_by_resources() method on AccessGrants
  • get_prompts_by_user_id() uses batch get_accessible_resource_ids()
    instead of per-prompt has_access() calls
  • search_prompts() batch-fetches grants instead of per-item
    _to_prompt_model() calls

For 30 prompts this reduces ~31 DB queries to ~3.

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/21616 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 2/19/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `perf-prompt-list` --- ### 📝 Commits (1) - [`ae9e9ee`](https://github.com/open-webui/open-webui/commit/ae9e9eebf00fa3e6055bfa6d8153073e8146ccc5) Eliminate N+1 access grant queries in prompts listing ### 📊 Changes **2 files changed** (+68 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/access_grants.py` (+30 -0) 📝 `backend/open_webui/models/prompts.py` (+38 -11) </details> ### 📄 Description The prompts listing endpoints were calling _get_access_grants() per prompt (N+1 queries) via _to_prompt_model(). Additionally, get_prompts_by_user_id() called has_access() per prompt for filtering (another N+1). Now: - get_prompts() batch-fetches all access grants in one query via new get_grants_by_resources() method on AccessGrants - get_prompts_by_user_id() uses batch get_accessible_resource_ids() instead of per-prompt has_access() calls - search_prompts() batch-fetches grants instead of per-item _to_prompt_model() calls For 30 prompts this reduces ~31 DB queries to ~3. ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> 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-30 01:32:24 -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#49212