From 5749f78262d3ad4d4e56c17a2b71e3f2abc823cf Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:24:09 +0100 Subject: [PATCH] fix: reduce triple query to single fetch in model toggle (#21009) --- backend/open_webui/models/models.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/models/models.py b/backend/open_webui/models/models.py index 42ae2e8dd..5a59861dd 100755 --- a/backend/open_webui/models/models.py +++ b/backend/open_webui/models/models.py @@ -394,17 +394,16 @@ class ModelsTable: ) -> Optional[ModelModel]: with get_db_context(db) as db: try: - is_active = db.query(Model).filter_by(id=id).first().is_active + model = db.query(Model).filter_by(id=id).first() + if not model: + return None - db.query(Model).filter_by(id=id).update( - { - "is_active": not is_active, - "updated_at": int(time.time()), - } - ) + model.is_active = not model.is_active + model.updated_at = int(time.time()) db.commit() + db.refresh(model) - return self.get_model_by_id(id, db=db) + return ModelModel.model_validate(model) except Exception: return None