mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #24288] perf: filter prompt list in SQL instead of N+1 has_access loop #66443
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/24288
Author: @Classic298
Created: 5/1/2026
Status: 🔄 Open
Base:
dev← Head:perf/prompts-list-n1-fix📝 Commits (1)
576fc39perf(prompts): filter prompt list in SQL instead of N+1 has_access loop📊 Changes
1 file changed (+47 additions, -16 deletions)
View changed files
📝
backend/open_webui/models/prompts.py(+47 -16)📄 Description
get_prompts_by_user_id used to fetch every active prompt (with users + all access grants), then call AccessGrants.has_access() once per prompt that the user did not own. With 600+ prompts this issued ~600 extra round-trips per request and explained the multi-second delay reported in the GET /api/v1/prompts and /api/v1/prompts/tags endpoints for non-admin users.
Push the access check into a single SQL query via the existing AccessGrants.has_permission_filter (EXISTS subquery), so only accessible rows come back from the DB. Users and access grants for the surviving rows are still batch-fetched, no N+1 anywhere on this path.
Fixes https://github.com/open-webui/open-webui/discussions/24258
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.