feat(缓存): 添加批量清除用户相关缓存功能并优化缓存键命名
Build docker and publish / build (20.15.1) (push) Successful in 7m11s
Build docker and publish / build (20.15.1) (push) Successful in 7m11s
添加 BatchClearRelatedCache 方法用于批量清除用户相关缓存 优化设备相关缓存键的命名格式以提高一致性 简化设备登录逻辑中孤儿认证方法的处理流程
This commit is contained in:
@@ -274,10 +274,13 @@ func (l *BindEmailWithVerificationLogic) transferDeviceToEmailUser(deviceUserId,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 5. 清除邮箱用户缓存(确保获取最新数据)
|
||||
// 5. 强制清除邮箱用户的所有相关缓存(确保获取最新数据)// 清除邮箱用户缓存
|
||||
emailUser, _ := l.svcCtx.UserModel.FindOne(l.ctx, emailUserId)
|
||||
if emailUser != nil {
|
||||
l.svcCtx.UserModel.ClearUserCache(l.ctx, emailUser)
|
||||
// 清除用户的批量相关缓存(包括设备、认证方法等)
|
||||
if err := l.svcCtx.UserModel.BatchClearRelatedCache(l.ctx, emailUser); err != nil {
|
||||
l.Errorw("清理邮箱用户相关缓存失败", logger.Field("error", err.Error()), logger.Field("user_id", emailUser.Id))
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 清除设备相关缓存
|
||||
@@ -388,11 +391,13 @@ func (l *BindEmailWithVerificationLogic) createEmailUser(email string) (int64, e
|
||||
func (l *BindEmailWithVerificationLogic) clearDeviceRelatedCache(deviceIdentifier string, oldUserId, newUserId int64) {
|
||||
// 清除设备相关的缓存键
|
||||
deviceCacheKeys := []string{
|
||||
fmt.Sprintf("device:%s", deviceIdentifier),
|
||||
fmt.Sprintf("user_device:%d", oldUserId),
|
||||
fmt.Sprintf("user_device:%d", newUserId),
|
||||
fmt.Sprintf("user_auth:%d", oldUserId),
|
||||
fmt.Sprintf("user_auth:%d", newUserId),
|
||||
fmt.Sprintf("cache:device:identifier:%s", deviceIdentifier),
|
||||
fmt.Sprintf("cache:user:devices:%d", oldUserId),
|
||||
fmt.Sprintf("cache:user:devices:%d", newUserId),
|
||||
fmt.Sprintf("cache:user:auth_methods:%d", oldUserId),
|
||||
fmt.Sprintf("cache:user:auth_methods:%d", newUserId),
|
||||
fmt.Sprintf("cache:user:%d", oldUserId),
|
||||
fmt.Sprintf("cache:user:%d", newUserId),
|
||||
}
|
||||
|
||||
for _, key := range deviceCacheKeys {
|
||||
|
||||
Reference in New Issue
Block a user