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{})
| 269 | // auth-version fence. It intentionally does nothing when the complete hash is |
| 270 | // absent; the next GetUserCache call will repopulate it from the database. |
| 271 | func updateUserCacheField(userId int, field string, value interface{}) error { |
| 272 | if !common.RedisEnabled { |
| 273 | return nil |
| 274 | } |
| 275 | var user User |
| 276 | if err := DB.Select("id", "auth_version").Where("id = ?", userId).First(&user).Error; err != nil { |
| 277 | return err |
| 278 | } |
| 279 | if user.AuthVersion <= 0 { |
| 280 | return fmt.Errorf("invalid user auth version") |
| 281 | } |
| 282 | return updateUserCacheFieldAtVersion(userId, field, value, user.AuthVersion) |
| 283 | } |
| 284 | |
| 285 | // GetUserLanguage returns the user's language preference from cache |
| 286 | // Uses the existing GetUserCache mechanism for efficiency |
no test coverage detected