mirror of
https://github.com/open-webui/open-webui.git
synced 2026-04-25 17:15:16 +02:00
perf: fix N+1 query issues in user group access control validation
- Pre-fetch user group IDs in get_*_by_user_id methods across models layer - Pass user_group_ids to has_access to avoid repeated group queries - Reduce query count from 1+N to 1+1 pattern for access control validation - Apply consistent optimization across knowledge, models, notes, prompts, and tools Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import uuid
|
||||
from typing import Optional
|
||||
|
||||
from open_webui.internal.db import Base, get_db
|
||||
from open_webui.models.groups import Groups
|
||||
from open_webui.utils.access_control import has_access
|
||||
from open_webui.models.users import Users, UserResponse
|
||||
|
||||
@@ -105,11 +106,12 @@ class NoteTable:
|
||||
self, user_id: str, permission: str = "write"
|
||||
) -> list[NoteModel]:
|
||||
notes = self.get_notes()
|
||||
user_group_ids = {group.id for group in Groups.get_groups_by_member_id(user_id)}
|
||||
return [
|
||||
note
|
||||
for note in notes
|
||||
if note.user_id == user_id
|
||||
or has_access(user_id, permission, note.access_control)
|
||||
or has_access(user_id, permission, note.access_control, user_group_ids)
|
||||
]
|
||||
|
||||
def get_note_by_id(self, id: str) -> Optional[NoteModel]:
|
||||
|
||||
Reference in New Issue
Block a user