From 5efb40253228e5fa53cbf3ee5b3308b124572b9c Mon Sep 17 00:00:00 2001 From: wans10 Date: Tue, 3 Feb 2026 09:48:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(model):=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将全局更新改为字段映射更新 - 移除不必要的会话配置选项 - 使用显式字段映射替代 Omit 和 Select 操作 - 提升代码可读性和维护性 - 保持数据一致性的同时提高性能 --- model/model_meta.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/model/model_meta.go b/model/model_meta.go index 465d15f1d..751965f52 100644 --- a/model/model_meta.go +++ b/model/model_meta.go @@ -61,12 +61,18 @@ func IsModelNameDuplicated(id int, name string) (bool, error) { func (mi *Model) Update() error { mi.UpdatedTime = common.GetTimestamp() - return DB.Session(&gorm.Session{AllowGlobalUpdate: false, FullSaveAssociations: false}). - Model(&Model{}). - Where("id = ?", mi.Id). - Omit("created_time"). - Select("*"). - Updates(mi).Error + return DB.Model(&Model{}).Where("id = ?", mi.Id).Updates(map[string]interface{}{ + "model_name": mi.ModelName, + "description": mi.Description, + "icon": mi.Icon, + "tags": mi.Tags, + "vendor_id": mi.VendorID, + "endpoints": mi.Endpoints, + "status": mi.Status, + "sync_official": mi.SyncOfficial, + "name_rule": mi.NameRule, + "updated_time": mi.UpdatedTime, + }).Error } func (mi *Model) Delete() error {