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

Function GetUserGroup

model/user.go:607–632  ·  view source on GitHub ↗

GetUserGroup gets group from Redis first, falls back to DB if needed

(id int, fromDB bool)

Source from the content-addressed store, hash-verified

605
606// GetUserGroup gets group from Redis first, falls back to DB if needed
607func GetUserGroup(id int, fromDB bool) (group string, err error) {
608 defer func() {
609 // Update Redis cache asynchronously on successful DB read
610 if shouldUpdateRedis(fromDB, err) {
611 gopool.Go(func() {
612 if err := updateUserGroupCache(id, group); err != nil {
613 common.SysError("failed to update user group cache: " + err.Error())
614 }
615 })
616 }
617 }()
618 if !fromDB && common.RedisEnabled {
619 group, err := getUserGroupCache(id)
620 if err == nil {
621 return group, nil
622 }
623 // Don't return error - fall through to DB
624 }
625 fromDB = true
626 err = DB.Model(&User{}).Where("id = ?", id).Select(commonGroupCol).Find(&group).Error
627 if err != nil {
628 return "", err
629 }
630
631 return group, nil
632}
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) {

Callers 6

testChannelFunction · 0.92
ListModelsFunction · 0.92
RequestEpayFunction · 0.92
RequestAmountFunction · 0.92
GetUserGroupsFunction · 0.92
RequestAmountMethod · 0.92

Calls 5

SysErrorFunction · 0.92
shouldUpdateRedisFunction · 0.85
updateUserGroupCacheFunction · 0.85
getUserGroupCacheFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected