fix: add lock when update quota (close #399)

This commit is contained in:
JustSong
2023-08-12 18:25:18 +08:00
parent 7bddc73b96
commit eae9b6e607
3 changed files with 6 additions and 6 deletions

View File

@@ -141,7 +141,7 @@ func UpdateChannelStatusById(id int, status int) {
}
func UpdateChannelUsedQuota(id int, quota int) {
err := DB.Model(&Channel{}).Where("id = ?", id).Update("used_quota", gorm.Expr("used_quota + ?", quota)).Error
err := DB.Set("gorm:query_option", "FOR UPDATE").Model(&Channel{}).Where("id = ?", id).Update("used_quota", gorm.Expr("used_quota + ?", quota)).Error
if err != nil {
common.SysError("failed to update channel used quota: " + err.Error())
}