From 3aae5d262c04f1dcc5b5b10077ea413303b644d0 Mon Sep 17 00:00:00 2001 From: Martial BE Date: Wed, 13 Mar 2024 18:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Update=20channel=20result?= =?UTF-8?q?s=20in=20data=20loss=20(#108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/channel.go | 6 +++++- model/channel.go | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/controller/channel.go b/controller/channel.go index 3c7402d3..8ad724fd 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -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, diff --git a/model/channel.go b/model/channel.go index 3a68885e..fa033d77 100644 --- a/model/channel.go +++ b/model/channel.go @@ -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 }