GetUserCache gets complete user cache from hash
(userId int)
| 92 | |
| 93 | // GetUserCache gets complete user cache from hash |
| 94 | func GetUserCache(userId int) (*UserBase, error) { |
| 95 | // Try getting from Redis first |
| 96 | userCache, err := cacheGetUserBase(userId) |
| 97 | if err == nil { |
| 98 | return userCache, nil |
| 99 | } |
| 100 | |
| 101 | // Redis misses and read failures both fall back to the shared database. A |
| 102 | // version fence newer than the database is the one exception: allowing that |
| 103 | // snapshot would re-authorize a user while a restrictive update is pending. |
| 104 | user, err := GetUserById(userId, false) |
| 105 | if err != nil { |
| 106 | return nil, err |
| 107 | } |
| 108 | if common.RedisEnabled { |
| 109 | floor, floorErr := getUserAuthVersionFloor(userId) |
| 110 | if floorErr == nil && floor > user.AuthVersion { |
| 111 | return nil, ErrUserAuthCachePending |
| 112 | } |
| 113 | if err := populateUserCache(*user); err != nil { |
| 114 | if errors.Is(err, ErrUserAuthCachePending) { |
| 115 | return nil, err |
| 116 | } |
| 117 | common.SysLog("failed to synchronously populate user cache: " + err.Error()) |
| 118 | } |
| 119 | } |
| 120 | return user.ToBaseUser(), nil |
| 121 | } |
| 122 | |
| 123 | func cacheGetUserBase(userId int) (*UserBase, error) { |
| 124 | if !common.RedisEnabled { |