Files
open-webui/backend/open_webui/models
Classic298 d67bc4ffcd perf: batch the file access check queries (#27383)
has_access_to_file runs for every non-owner file GET, per RAG file check and per shared-chat or model-attached file. Its final step called Models.get_models_by_user_id, which issued one grant query per non-owned workspace model, so a single file check on an instance with M workspace models cost M grant queries plus a group query, with the deny path always paying full price. Its collection_name step listed every knowledge base the user can access (itself one grant query per knowledge base) just to scan the list for one id. And get_accessible_folder_files repeated the whole pipeline per folder entry, refetching the caller's group memberships every time.

Three changes, all using parameters and helpers that already exist:
- Models.get_models_by_user_id resolves grants for all non-owned models in one get_accessible_resource_ids call and accepts prefetched user_group_ids.
- The collection_name check fetches the one referenced knowledge base and performs a single owner-or-grant check with the already-resolved group ids, preserving the write-requires-owner guard exactly (including its short-circuit before any grant query).
- get_accessible_folder_files resolves group ids once and threads them through every per-entry check.

Benchmark:

| metric | before | after |
| --- | --- | --- |
| filter loop CPU, 300 workspace models (queries stubbed) | 47 us | 19 us |
| grant queries per file-access check, M workspace models | M | 1 |
| group membership queries per folder listing, F files | F | 1 |

The stubbed CPU row understates the win: each removed query in the other two rows was a real database round trip.

Functionally verified with stubbed accessors: owned plus granted models are returned with owned ids excluded from the batch query; model-attached file access resolves through the batched path; the collection_name path does one KB fetch and one grant check with no full listing; a missing KB falls through; write access via a KB still requires the KB owner to own the file and short-circuits before the grant query; folder listings fetch groups exactly once.
2026-07-23 17:50:08 -05:00
..
2026-06-29 03:16:59 -05:00
2026-06-01 14:09:54 -07:00
2026-07-20 01:33:47 -04:00
2026-07-23 04:01:30 -04:00
2026-07-23 04:16:14 -04:00
2026-06-29 13:03:14 -05:00
2026-06-29 13:03:14 -05:00
2026-07-23 13:41:16 -04:00
2026-07-17 04:48:21 -04:00
2026-06-29 13:03:14 -05:00
2026-06-29 13:03:14 -05:00
2026-07-17 06:50:16 -04:00
2026-06-01 13:56:55 -07:00
2026-07-17 04:11:11 -04:00
2026-06-01 13:56:55 -07:00
2026-06-29 13:03:14 -05:00
2026-07-23 14:29:27 -04:00