(id int, key string, quota int)
| 317 | } |
| 318 | |
| 319 | func DecreaseTokenQuota(id int, key string, quota int) (err error) { |
| 320 | if quota < 0 { |
| 321 | return errors.New("quota 不能为负数!") |
| 322 | } |
| 323 | if common.RedisEnabled { |
| 324 | gopool.Go(func() { |
| 325 | err := cacheDecrTokenQuota(key, int64(quota)) |
| 326 | if err != nil { |
| 327 | common.SysError("failed to decrease token quota: " + err.Error()) |
| 328 | } |
| 329 | }) |
| 330 | } |
| 331 | if common.BatchUpdateEnabled { |
| 332 | addNewRecord(BatchUpdateTypeTokenQuota, id, -quota) |
| 333 | return nil |
| 334 | } |
| 335 | return decreaseTokenQuota(id, quota) |
| 336 | } |
| 337 | |
| 338 | func decreaseTokenQuota(id int, quota int) (err error) { |
| 339 | err = DB.Model(&Token{}).Where("id = ?", id).Updates( |
no test coverage detected