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

Function DecreaseTokenQuota

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

Source from the content-addressed store, hash-verified

410}
411
412func 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
431func decreaseTokenQuota(id int, quota int) (err error) {
432 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