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