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

Function GetUserQuota

model/user.go:569–594  ·  view source on GitHub ↗

GetUserQuota gets quota from Redis first, falls back to DB if needed

(id int, fromDB bool)

Source from the content-addressed store, hash-verified

567
568// GetUserQuota gets quota from Redis first, falls back to DB if needed
569func GetUserQuota(id int, fromDB bool) (quota int, err error) {
570 defer func() {
571 // Update Redis cache asynchronously on successful DB read
572 if shouldUpdateRedis(fromDB, err) {
573 gopool.Go(func() {
574 if err := updateUserQuotaCache(id, quota); err != nil {
575 common.SysError("failed to update user quota cache: " + err.Error())
576 }
577 })
578 }
579 }()
580 if !fromDB && common.RedisEnabled {
581 quota, err := getUserQuotaCache(id)
582 if err == nil {
583 return quota, nil
584 }
585 // Don't return error - fall through to DB
586 }
587 fromDB = true
588 err = DB.Model(&User{}).Where("id = ?", id).Select("quota").Find(&quota).Error
589 if err != nil {
590 return 0, err
591 }
592
593 return quota, nil
594}
595
596func GetUserUsedQuota(id int) (quota int, err error) {
597 err = DB.Model(&User{}).Where("id = ?", id).Select("used_quota").Find(&quota).Error

Callers 7

GetSubscriptionFunction · 0.92
PreWssConsumeQuotaFunction · 0.92
RelaySwapFaceFunction · 0.92
RelayMidjourneySubmitFunction · 0.92
ImageHelperFunction · 0.92
preConsumeQuotaFunction · 0.92
RelayTaskSubmitFunction · 0.92

Calls 5

SysErrorFunction · 0.92
shouldUpdateRedisFunction · 0.85
updateUserQuotaCacheFunction · 0.85
getUserQuotaCacheFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected