Skip to content

Commit 0c8db4f

Browse files
committed
refactor(model): 优化模型更新逻辑
- 将全局更新改为字段映射更新 - 移除不必要的会话配置选项 - 使用显式字段映射替代 Omit 和 Select 操作 - 提升代码可读性和维护性 - 保持数据一致性的同时提高性能
1 parent 112dd80 commit 0c8db4f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

model/model_meta.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@ func IsModelNameDuplicated(id int, name string) (bool, error) {
6161

6262
func (mi *Model) Update() error {
6363
mi.UpdatedTime = common.GetTimestamp()
64-
return DB.Session(&gorm.Session{AllowGlobalUpdate: false, FullSaveAssociations: false}).
65-
Model(&Model{}).
66-
Where("id = ?", mi.Id).
67-
Omit("created_time").
68-
Select("*").
69-
Updates(mi).Error
64+
return DB.Model(&Model{}).Where("id = ?", mi.Id).Updates(map[string]interface{}{
65+
"model_name": mi.ModelName,
66+
"description": mi.Description,
67+
"icon": mi.Icon,
68+
"tags": mi.Tags,
69+
"vendor_id": mi.VendorID,
70+
"endpoints": mi.Endpoints,
71+
"status": mi.Status,
72+
"sync_official": mi.SyncOfficial,
73+
"name_rule": mi.NameRule,
74+
"updated_time": mi.UpdatedTime,
75+
}).Error
7076
}
7177

7278
func (mi *Model) Delete() error {

0 commit comments

Comments
 (0)