(id int, quota int, db bool)
| 1255 | } |
| 1256 | |
| 1257 | func DecreaseUserQuota(id int, quota int, db bool) (err error) { |
| 1258 | if quota < 0 { |
| 1259 | return errors.New("quota 不能为负数!") |
| 1260 | } |
| 1261 | gopool.Go(func() { |
| 1262 | err := cacheDecrUserQuota(id, int64(quota)) |
| 1263 | if err != nil { |
| 1264 | common.SysLog("failed to decrease user quota: " + err.Error()) |
| 1265 | } |
| 1266 | }) |
| 1267 | if !db && common.BatchUpdateEnabled { |
| 1268 | addNewRecord(BatchUpdateTypeUserQuota, id, -quota) |
| 1269 | return nil |
| 1270 | } |
| 1271 | return decreaseUserQuota(id, quota) |
| 1272 | } |
| 1273 | |
| 1274 | func decreaseUserQuota(id int, quota int) (err error) { |
| 1275 | err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error |
no test coverage detected