(id int, quota int, db bool)
| 1293 | } |
| 1294 | |
| 1295 | func DecreaseUserQuota(id int, quota int, db bool) (err error) { |
| 1296 | if quota < 0 { |
| 1297 | return errors.New("quota 不能为负数!") |
| 1298 | } |
| 1299 | gopool.Go(func() { |
| 1300 | err := cacheDecrUserQuota(id, int64(quota)) |
| 1301 | if err != nil { |
| 1302 | common.SysLog("failed to decrease user quota: " + err.Error()) |
| 1303 | } |
| 1304 | }) |
| 1305 | if !db && common.BatchUpdateEnabled { |
| 1306 | addNewRecord(BatchUpdateTypeUserQuota, id, -quota) |
| 1307 | return nil |
| 1308 | } |
| 1309 | return decreaseUserQuota(id, quota) |
| 1310 | } |
| 1311 | |
| 1312 | func decreaseUserQuota(id int, quota int) (err error) { |
| 1313 | err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error |
no test coverage detected