MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / GetUserSetting

Function GetUserSetting

model/user.go:635–663  ·  view source on GitHub ↗

GetUserSetting gets setting from Redis first, falls back to DB if needed

(id int, fromDB bool)

Source from the content-addressed store, hash-verified

633
634// GetUserSetting gets setting from Redis first, falls back to DB if needed
635func GetUserSetting(id int, fromDB bool) (settingMap dto.UserSetting, err error) {
636 var setting string
637 defer func() {
638 // Update Redis cache asynchronously on successful DB read
639 if shouldUpdateRedis(fromDB, err) {
640 gopool.Go(func() {
641 if err := updateUserSettingCache(id, setting); err != nil {
642 common.SysError("failed to update user setting cache: " + err.Error())
643 }
644 })
645 }
646 }()
647 if !fromDB && common.RedisEnabled {
648 setting, err := getUserSettingCache(id)
649 if err == nil {
650 return setting, nil
651 }
652 // Don't return error - fall through to DB
653 }
654 fromDB = true
655 err = DB.Model(&User{}).Where("id = ?", id).Select("setting").Find(&setting).Error
656 if err != nil {
657 return settingMap, err
658 }
659 userBase := &UserBase{
660 Setting: setting,
661 }
662 return userBase.GetSetting(), nil
663}
664
665func IncreaseUserQuota(id int, quota int, db bool) (err error) {
666 if quota < 0 {

Callers 2

RecordErrorLogFunction · 0.85
RecordConsumeLogFunction · 0.85

Calls 6

GetSettingMethod · 0.95
SysErrorFunction · 0.92
shouldUpdateRedisFunction · 0.85
updateUserSettingCacheFunction · 0.85
getUserSettingCacheFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected