🐛 fix: Update channel results in data loss (#108)

This commit is contained in:
Martial BE 2024-03-13 18:34:37 +08:00
parent 05347bc9a1
commit 3aae5d262c
No known key found for this signature in database
GPG Key ID: D06C32DF0EDB9084
2 changed files with 13 additions and 4 deletions

View File

@ -132,7 +132,11 @@ func UpdateChannel(c *gin.Context) {
})
return
}
err = channel.Update()
if channel.Models == "" {
err = channel.Update(false)
} else {
err = channel.Update(true)
}
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,

View File

@ -152,7 +152,7 @@ func BatchDelModelChannels(params *BatchChannelsParams) (int64, error) {
}
channel.Models = strings.Join(modelsSlice, ",")
channel.Update()
channel.Update(false)
count++
}
@ -190,9 +190,14 @@ func (channel *Channel) Insert() error {
return err
}
func (channel *Channel) Update() error {
func (channel *Channel) Update(overwrite bool) error {
var err error
err = DB.Model(channel).Select("*").Omit("UsedQuota").Updates(channel).Error
if overwrite {
err = DB.Model(channel).Select("*").Omit("UsedQuota").Updates(channel).Error
} else {
err = DB.Model(channel).Omit("UsedQuota").Updates(channel).Error
}
if err != nil {
return err
}