MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / DecreaseTokenQuota

Function DecreaseTokenQuota

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

Source from the content-addressed store, hash-verified

317}
318
319func 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
338func decreaseTokenQuota(id int, quota int) (err error) {
339 err = DB.Model(&Token{}).Where("id = ?", id).Updates(

Callers 2

PreConsumeTokenQuotaFunction · 0.92
PostConsumeQuotaFunction · 0.92

Calls 5

SysErrorFunction · 0.92
cacheDecrTokenQuotaFunction · 0.85
addNewRecordFunction · 0.85
decreaseTokenQuotaFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected