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