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

Function DecreaseUserQuota

model/user.go:690–705  ·  view source on GitHub ↗
(id int, quota int)

Source from the content-addressed store, hash-verified

688}
689
690func DecreaseUserQuota(id int, quota int) (err error) {
691 if quota < 0 {
692 return errors.New("quota 不能为负数!")
693 }
694 gopool.Go(func() {
695 err := cacheDecrUserQuota(id, int64(quota))
696 if err != nil {
697 common.SysError("failed to decrease user quota: " + err.Error())
698 }
699 })
700 if common.BatchUpdateEnabled {
701 addNewRecord(BatchUpdateTypeUserQuota, id, -quota)
702 return nil
703 }
704 return decreaseUserQuota(id, quota)
705}
706
707func decreaseUserQuota(id int, quota int) (err error) {
708 err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error

Callers 3

PostConsumeQuotaFunction · 0.92
preConsumeQuotaFunction · 0.92
DeltaUpdateUserQuotaFunction · 0.85

Calls 5

SysErrorFunction · 0.92
cacheDecrUserQuotaFunction · 0.85
addNewRecordFunction · 0.85
decreaseUserQuotaFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected