mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 03:43:39 +00:00
refactor(model): 优化模型更新逻辑
- 将全局更新改为字段映射更新 - 移除不必要的会话配置选项 - 使用显式字段映射替代 Omit 和 Select 操作 - 提升代码可读性和维护性 - 保持数据一致性的同时提高性能
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user