mirror of
https://github.com/open-webui/open-webui.git
synced 2026-03-24 20:14:58 -05:00
issue: Performance bottleneck in /api/models: excessive DB queries in get_all_models and access filtering #5420
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?
Originally created by @escargotbuffed on GitHub (Jun 2, 2025).
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.6.13
Ollama Version (if applicable)
No response
Operating System
Ubuntu 22.04
Browser (if applicable)
No response
Confirmation
README.md.Expected Behavior
GET /api/modelsshould return a filtered list of models within a few hundred milliseconds at most.Actual Behavior
The response time for
GET /api/modelsoften exceeds 7–8 seconds.Profiling shows two main hotspots:
get_all_models(≈ 4.5 s) — fetching/merging every model from external sourcesarena=true, the code invokesModels.get_model_by_id(model_id)(1 DB query per model) followed—if the user is not the owner—byhas_access(...), which itself callsGroups.get_groups_by_member_id(user_id)(another DB query per model)Because there are O(40–50) models, the combined effect is tens of database round-trips in sequence, causing a multi-second delay before any data is returned to the client.
Even though Redis is configured, the final filtered model list is not being cached. Every request re-executes all database queries against the remote Postgres instance.
Steps to Reproduce
Ensure the application is pointed at a remote (non‐local) PostgreSQL database instance.
Authenticate as a normal user (role = “user”) who owns or has permission on a subset of models.
Issue a request to the
/api/modelsendpoint:Observe the response time in your browser’s network tab (it will typically take around 8 seconds).
Logs & Screenshots
Additional Information
Database & Cache Configuration
postgres://user:pass@db.example.com:5432/open_webui)./api/models.Why This Matters