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

Function DecreaseUserQuota

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

Source from the content-addressed store, hash-verified

1255}
1256
1257func DecreaseUserQuota(id int, quota int, db bool) (err error) {
1258 if quota < 0 {
1259 return errors.New("quota 不能为负数!")
1260 }
1261 gopool.Go(func() {
1262 err := cacheDecrUserQuota(id, int64(quota))
1263 if err != nil {
1264 common.SysLog("failed to decrease user quota: " + err.Error())
1265 }
1266 })
1267 if !db && common.BatchUpdateEnabled {
1268 addNewRecord(BatchUpdateTypeUserQuota, id, -quota)
1269 return nil
1270 }
1271 return decreaseUserQuota(id, quota)
1272}
1273
1274func decreaseUserQuota(id int, quota int) (err error) {
1275 err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error

Callers 7

ManageUserFunction · 0.92
PostConsumeQuotaFunction · 0.92
taskAdjustFundingFunction · 0.92
PreConsumeMethod · 0.92
SettleMethod · 0.92
reserveFundingMethod · 0.92
DeltaUpdateUserQuotaFunction · 0.85

Calls 5

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

Tested by

no test coverage detected