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

Function DecreaseTokenQuota

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

Source from the content-addressed store, hash-verified

406}
407
408func 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
426func decreaseTokenQuota(id int, quota int) (err error) {
427 err = DB.Model(&Token{}).Where("id = ?", id).Updates(

Callers 4

taskAdjustTokenQuotaFunction · 0.92
SettleMethod · 0.92
TryReserveTokenQuotaFunction · 0.85

Calls 5

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

Tested by

no test coverage detected