Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: Update channel results in data loss (lobehub#108)
Browse files Browse the repository at this point in the history
MartialBE committed Mar 13, 2024
1 parent 05347bc commit 3aae5d2
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion controller/channel.go
Original file line number Diff line number Diff line change
@@ -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,
11 changes: 8 additions & 3 deletions model/channel.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 3aae5d2

Please sign in to comment.