(id int, key string, quota int)
| 411 | } |
| 412 | |
| 413 | func DecreaseTokenQuota(id int, key string, quota int) (err error) { |
| 414 | if quota < 0 { |
| 415 | return errors.New("quota cannot be negative") |
| 416 | } |
| 417 | if common.RedisEnabled { |
| 418 | gopool.Go(func() { |
| 419 | if _, err := cacheApplyTokenQuotaDelta(id, key, int64(-quota)); err != nil { |
| 420 | common.SysLog(common.LogText("failed to decrease token quota: %s", 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