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

Function GetUserCache

model/user_cache.go:73–112  ·  view source on GitHub ↗

GetUserCache gets complete user cache from hash

(userId int)

Source from the content-addressed store, hash-verified

71
72// GetUserCache gets complete user cache from hash
73func GetUserCache(userId int) (userCache *UserBase, err error) {
74 var user *User
75 var fromDB bool
76 defer func() {
77 // Update Redis cache asynchronously on successful DB read
78 if shouldUpdateRedis(fromDB, err) && user != nil {
79 gopool.Go(func() {
80 if err := updateUserCache(*user); err != nil {
81 common.SysError("failed to update user status cache: " + err.Error())
82 }
83 })
84 }
85 }()
86
87 // Try getting from Redis first
88 userCache, err = cacheGetUserBase(userId)
89 if err == nil {
90 return userCache, nil
91 }
92
93 // If Redis fails, get from DB
94 fromDB = true
95 user, err = GetUserById(userId, false)
96 if err != nil {
97 return nil, err // Return nil and error if DB lookup fails
98 }
99
100 // Create cache object from user data
101 userCache = &UserBase{
102 Id: user.Id,
103 Group: user.Group,
104 Quota: user.Quota,
105 Status: user.Status,
106 Username: user.Username,
107 Setting: user.Setting,
108 Email: user.Email,
109 }
110
111 return userCache, nil
112}
113
114func cacheGetUserBase(userId int) (*UserBase, error) {
115 if !common.RedisEnabled {

Callers 10

TokenAuthFunction · 0.92
testChannelFunction · 0.92
PlaygroundFunction · 0.92
GetPricingFunction · 0.92
GetUserModelsFunction · 0.92
getUserGroupCacheFunction · 0.85
getUserQuotaCacheFunction · 0.85
getUserStatusCacheFunction · 0.85
getUserNameCacheFunction · 0.85
getUserSettingCacheFunction · 0.85

Calls 6

SysErrorFunction · 0.92
shouldUpdateRedisFunction · 0.85
updateUserCacheFunction · 0.85
cacheGetUserBaseFunction · 0.85
GetUserByIdFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected