updateUserCacheField prevents individual cache refreshes from bypassing the auth-version fence. It intentionally does nothing when the complete hash is absent; the next GetUserCache call will repopulate it from the database.
(userId int, field string, value interface{})
| 254 | // auth-version fence. It intentionally does nothing when the complete hash is |
| 255 | // absent; the next GetUserCache call will repopulate it from the database. |
| 256 | func updateUserCacheField(userId int, field string, value interface{}) error { |
| 257 | if !common.RedisEnabled { |
| 258 | return nil |
| 259 | } |
| 260 | var user User |
| 261 | if err := DB.Select("id", "auth_version").Where("id = ?", userId).First(&user).Error; err != nil { |
| 262 | return err |
| 263 | } |
| 264 | if user.AuthVersion <= 0 { |
| 265 | return fmt.Errorf("invalid user auth version") |
| 266 | } |
| 267 | return updateUserCacheFieldAtVersion(userId, field, value, user.AuthVersion) |
| 268 | } |
| 269 | |
| 270 | // GetUserLanguage returns the user's language preference from cache |
| 271 | // Uses the existing GetUserCache mechanism for efficiency |
no test coverage detected