(id int, key string, quota int)
| 410 | } |
| 411 | |
| 412 | func DecreaseTokenQuota(id int, key string, quota int) (err error) { |
| 413 | if quota < 0 { |
| 414 | return errors.New("quota 不能为负数!") |
| 415 | } |
| 416 | if common.RedisEnabled { |
| 417 | gopool.Go(func() { |
| 418 | err := cacheDecrTokenQuota(key, int64(quota)) |
| 419 | if err != nil { |
| 420 | common.SysLog("failed to decrease token quota: " + err.Error()) |
| 421 | } |
| 422 | }) |
| 423 | } |
| 424 | if common.BatchUpdateEnabled { |
| 425 | addNewRecord(BatchUpdateTypeTokenQuota, id, -quota) |
| 426 | return nil |
| 427 | } |
| 428 | return decreaseTokenQuota(id, quota) |
| 429 | } |
| 430 | |
| 431 | func decreaseTokenQuota(id int, quota int) (err error) { |
| 432 | err = DB.Model(&Token{}).Where("id = ?", id).Updates( |
no test coverage detected