Skip to content

Commit 53eadb7

Browse files
committed
refac
1 parent 6c24366 commit 53eadb7

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

backend/open_webui/models/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def update_model_by_id(self, id: str, model: ModelForm, db: Optional[Session] =
414414
with get_db_context(db) as db:
415415
# update only the fields that are present in the model
416416
data = model.model_dump(exclude={'id', 'access_grants'})
417+
data['updated_at'] = int(time.time())
417418
result = db.query(Model).filter_by(id=id).update(data)
418419

419420
db.commit()
@@ -425,6 +426,20 @@ def update_model_by_id(self, id: str, model: ModelForm, db: Optional[Session] =
425426
log.exception(f'Failed to update the model by id {id}: {e}')
426427
return None
427428

429+
def update_model_updated_at_by_id(self, id: str, db: Optional[Session] = None) -> Optional[ModelModel]:
430+
try:
431+
with get_db_context(db) as db:
432+
result = db.query(Model).filter_by(id=id).first()
433+
if not result:
434+
return None
435+
result.updated_at = int(time.time())
436+
db.commit()
437+
db.refresh(result)
438+
return self._to_model_model(result, db=db)
439+
except Exception as e:
440+
log.exception(f'Failed to update the model updated_at by id {id}: {e}')
441+
return None
442+
428443
def delete_model_by_id(self, id: str, db: Optional[Session] = None) -> bool:
429444
try:
430445
with get_db_context(db) as db:

backend/open_webui/routers/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ async def update_model_access_by_id(
578578

579579
AccessGrants.set_access_grants('model', form_data.id, form_data.access_grants, db=db)
580580

581+
Models.update_model_updated_at_by_id(form_data.id, db=db)
582+
581583
return Models.get_model_by_id(form_data.id, db=db)
582584

583585

0 commit comments

Comments
 (0)