mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[PR #17165] [MERGED] perf: fix N+1 query issue in tools access control checking #24344
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/17165
Author: @sihyeonn
Created: 9/2/2025
Status: ✅ Merged
Merged: 9/3/2025
Merged by: @tjbck
Base:
dev← Head:perf/sh-tools-router📝 Commits (1)
0503fbdperf: fix N+1 query issue in tools access control checking📊 Changes
2 files changed (+9 additions, -4 deletions)
View changed files
📝
backend/open_webui/routers/tools.py(+3 -1)📝
backend/open_webui/utils/access_control.py(+6 -3)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Fixed a critical N+1 query performance issue in the tools router where user group information was being fetched repeatedly for each tool during access control validation. This optimization pre-fetches user groups once per request and reuses the data for all subsequent access control checks, significantly reducing database load.
The fix leverages the existing optional
user_group_idsparameter in thehas_accessfunction to avoid redundant group queries when validating permissions for multiple tools.Changed
get_toolsendpoint to pre-fetch user group IDs once per requesthas_accesscalls to pass pre-fetcheduser_group_idsparameterhas_accessfunctionFixed
Additional Information
backend/open_webui/routers/tools.py(lines 75, 80)backend/open_webui/utils/access_control.py(function signature already supported optimization)1 + Nqueries to1 + 1queriesContributor 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.