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

Function DecreaseUserQuota

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

Source from the content-addressed store, hash-verified

1401}
1402
1403func DecreaseUserQuota(id int, quota int, db bool) (err error) {
1404 if quota < 0 {
1405 return errors.New("quota cannot be negative")
1406 }
1407 gopool.Go(func() {
1408 err := cacheDecrUserQuota(id, int64(quota))
1409 if err != nil {
1410 common.SysLog(common.LogText("failed to decrease user quota: %s", err.Error()))
1411 }
1412 })
1413 if !db && common.BatchUpdateEnabled {
1414 addNewRecord(BatchUpdateTypeUserQuota, id, -quota)
1415 return nil
1416 }
1417 return decreaseUserQuota(id, quota)
1418}
1419
1420func decreaseUserQuota(id int, quota int) (err error) {
1421 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