Merge commit from fork
* Harden user setting cache updates * Fix user update test isolation
This commit is contained in:
+31
-3
@@ -63,8 +63,7 @@ func InvalidateUserCache(userId int) error {
|
||||
return invalidateUserCache(userId)
|
||||
}
|
||||
|
||||
// updateUserCache updates all user cache fields using hash
|
||||
func updateUserCache(user User) error {
|
||||
func populateUserCache(user User) error {
|
||||
if !common.RedisEnabled {
|
||||
return nil
|
||||
}
|
||||
@@ -76,6 +75,28 @@ func updateUserCache(user User) error {
|
||||
)
|
||||
}
|
||||
|
||||
// updateUserCache refreshes non-quota user cache fields.
|
||||
// Quota is maintained by atomic quota delta paths and must not be overwritten
|
||||
// by stale user snapshots from profile/settings updates.
|
||||
func updateUserCache(user User) error {
|
||||
if !common.RedisEnabled {
|
||||
return nil
|
||||
}
|
||||
if err := updateUserGroupCache(user.Id, user.Group); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updateUserEmailCache(user.Id, user.Email); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updateUserStatusCache(user.Id, user.Status == common.UserStatusEnabled); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updateUserNameCache(user.Id, user.Username); err != nil {
|
||||
return err
|
||||
}
|
||||
return updateUserSettingCache(user.Id, user.Setting)
|
||||
}
|
||||
|
||||
// GetUserCache gets complete user cache from hash
|
||||
func GetUserCache(userId int) (userCache *UserBase, err error) {
|
||||
var user *User
|
||||
@@ -84,7 +105,7 @@ func GetUserCache(userId int) (userCache *UserBase, err error) {
|
||||
// Update Redis cache asynchronously on successful DB read
|
||||
if shouldUpdateRedis(fromDB, err) && user != nil {
|
||||
gopool.Go(func() {
|
||||
if err := updateUserCache(*user); err != nil {
|
||||
if err := populateUserCache(*user); err != nil {
|
||||
common.SysLog("failed to update user status cache: " + err.Error())
|
||||
}
|
||||
})
|
||||
@@ -214,6 +235,13 @@ func UpdateUserGroupCache(userId int, group string) error {
|
||||
return updateUserGroupCache(userId, group)
|
||||
}
|
||||
|
||||
func updateUserEmailCache(userId int, email string) error {
|
||||
if !common.RedisEnabled {
|
||||
return nil
|
||||
}
|
||||
return common.RedisHSetField(getUserCacheKey(userId), "Email", email)
|
||||
}
|
||||
|
||||
func updateUserNameCache(userId int, username string) error {
|
||||
if !common.RedisEnabled {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user