MCPcopy
hub / github.com/QuantumNous/new-api / GetUserGroup

Function GetUserGroup

model/user.go:830–855  ·  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

828
829// GetUserGroup gets group from Redis first, falls back to DB if needed
830func GetUserGroup(id int, fromDB bool) (group string, err error) {
831 defer func() {
832 // Update Redis cache asynchronously on successful DB read
833 if shouldUpdateRedis(fromDB, err) {
834 gopool.Go(func() {
835 if err := updateUserGroupCache(id, group); err != nil {
836 common.SysLog("failed to update user group cache: " + err.Error())
837 }
838 })
839 }
840 }()
841 if !fromDB && common.RedisEnabled {
842 group, err := getUserGroupCache(id)
843 if err == nil {
844 return group, nil
845 }
846 // Don't return error - fall through to DB
847 }
848 fromDB = true
849 err = DB.Model(&User{}).Where("id = ?", id).Select(commonGroupCol).Find(&group).Error
850 if err != nil {
851 return "", err
852 }
853
854 return group, nil
855}
856
857// GetUserSetting gets setting from Redis first, falls back to DB if needed
858func GetUserSetting(id int, fromDB bool) (settingMap dto.UserSetting, err error) {

Callers 10

testChannelFunction · 0.92
getModelListGroupsFunction · 0.92
RequestEpayFunction · 0.92
RequestAmountFunction · 0.92
GetUserGroupsFunction · 0.92
RequestAmountMethod · 0.92
RequestWaffoAmountFunction · 0.92
RequestWaffoPayFunction · 0.92
RequestWaffoPancakePayFunction · 0.92

Calls 5

SysLogFunction · 0.92
shouldUpdateRedisFunction · 0.85
updateUserGroupCacheFunction · 0.85
getUserGroupCacheFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected