perf: optimize /api/models endpoint performance using batched loading#20010
perf: optimize /api/models endpoint performance using batched loading#20010Classic298 wants to merge 1 commit intoopen-webui:devfrom
Conversation
Co-authored-by: Claude <[email protected]> Fixes: open-webui#20004, open-webui#18950
👋 Welcome and Thank You for Contributing!We appreciate you taking the time to submit a pull request to Open WebUI!
|
|
@silentoplayz very general simple testing wanted if this works thx |
Models API Optimization VerificationChanges Verified
Verification ProcessTwo Python scripts were created to verify the changes:
ResultsPerformance BenchmarkThe benchmark demonstrates that the number of database queries remains constant regardless of the number of models, confirming the O(1) query optimization.
Note: Results obtained from Access Control VerificationThe functional tests passed significantly, confirming that:
ConclusionThe optimization effectively reduces database load without compromising security or functionality. |
|
That was a splendid review! Thank you @silentoplayz |
Co-Authored-By: Classic298 <[email protected]> #20010
|
Closing in favour of 0dd2cfe! |
Co-Authored-By: Classic298 <[email protected]> open-webui#20010
Co-Authored-By: Classic298 <[email protected]> open-webui#20010
Fixes: #20004, #18950
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch. Not targeting thedevbranch will lead to immediate closure of the PR.Changelog Entry
Description
Optimizes /api/models endpoint performance by replacing sequential database queries with batch loading. The get_filtered_models() functions were calling Models.get_model_by_id() in a loop for each model, creating N database queries and loading heavy meta fields containing base64 profile images. This change reduces database queries from N to 1 and excludes unnecessary image data from access control checks.
Changed
Fixed
Security
Breaking Changes
Additional Information
Contributor 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.
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.