MCPcopy Create free account
hub / github.com/QuantumNous/new-api / DecreaseTokenQuota

Function DecreaseTokenQuota

model/token.go:435–452  ·  view source on GitHub ↗
(id int, key string, quota int)

Source from the content-addressed store, hash-verified

433}
434
435func 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
454func decreaseTokenQuota(id int, quota int) (err error) {
455 err = DB.Model(&Token{}).Where("id = ?", id).Updates(

Callers 4

PreConsumeTokenQuotaFunction · 0.92
PostConsumeQuotaFunction · 0.92
taskAdjustTokenQuotaFunction · 0.92
SettleMethod · 0.92

Calls 5

SysLogFunction · 0.92
cacheDecrTokenQuotaFunction · 0.85
addNewRecordFunction · 0.85
decreaseTokenQuotaFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected