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

Function DecreaseTokenQuota

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

Source from the content-addressed store, hash-verified

411}
412
413func DecreaseTokenQuota(id int, key string, quota int) (err error) {
414 if quota < 0 {
415 return errors.New("quota cannot be negative")
416 }
417 if common.RedisEnabled {
418 gopool.Go(func() {
419 if _, err := cacheApplyTokenQuotaDelta(id, key, int64(-quota)); err != nil {
420 common.SysLog(common.LogText("failed to decrease token quota: %s", 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

taskAdjustTokenQuotaFunction · 0.92
SettleMethod · 0.92
TryReserveTokenQuotaFunction · 0.85

Calls 6

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

Tested by

no test coverage detected