(id int, key string, quota int)
| 433 | } |
| 434 | |
| 435 | func DecreaseTokenQuota(id int, key string, quota int) (err error) { |
| 436 | if quota < 0 { |
| 437 | return errors.New("quota 不能为负数!") |
| 438 | } |
| 439 | if common.RedisEnabled { |
| 440 | gopool.Go(func() { |
| 441 | err := cacheDecrTokenQuota(key, int64(quota)) |
| 442 | if err != nil { |
| 443 | common.SysLog("failed to decrease token quota: " + err.Error()) |
| 444 | } |
| 445 | }) |
| 446 | } |
| 447 | if common.BatchUpdateEnabled { |
| 448 | addNewRecord(BatchUpdateTypeTokenQuota, id, -quota) |
| 449 | return nil |
| 450 | } |
| 451 | return decreaseTokenQuota(id, quota) |
| 452 | } |
| 453 | |
| 454 | func decreaseTokenQuota(id int, quota int) (err error) { |
| 455 | err = DB.Model(&Token{}).Where("id = ?", id).Updates( |
no test coverage detected