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

Function DecreaseUserQuota

model/user.go:1387–1402  ·  view source on GitHub ↗
(id int, quota int, db bool)

Source from the content-addressed store, hash-verified

1385}
1386
1387func DecreaseUserQuota(id int, quota int, db bool) (err error) {
1388 if quota < 0 {
1389 return errors.New("quota cannot be negative")
1390 }
1391 gopool.Go(func() {
1392 err := cacheDecrUserQuota(id, int64(quota))
1393 if err != nil {
1394 common.SysLog(common.LogText("failed to decrease user quota: %s", err.Error()))
1395 }
1396 })
1397 if !db && common.BatchUpdateEnabled {
1398 addNewRecord(BatchUpdateTypeUserQuota, id, -quota)
1399 return nil
1400 }
1401 return decreaseUserQuota(id, quota)
1402}
1403
1404func decreaseUserQuota(id int, quota int) (err error) {
1405 err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error

Callers 8

SettleMethod · 0.92
ReserveMethod · 0.92
taskAdjustFundingFunction · 0.92
SettleMethod · 0.92
reserveFundingMethod · 0.92
DeltaUpdateUserQuotaFunction · 0.85

Calls 6

SysLogFunction · 0.92
LogTextFunction · 0.92
cacheDecrUserQuotaFunction · 0.85
addNewRecordFunction · 0.85
decreaseUserQuotaFunction · 0.85
ErrorMethod · 0.45

Tested by 3

SettleMethod · 0.74
ReserveMethod · 0.74