更新用户时刷新缓存数据

This commit is contained in:
CaIon 2023-12-29 00:00:23 +08:00
parent 85411bc167
commit 7e4fe14871

View File

@ -6,6 +6,7 @@ import (
"gorm.io/gorm"
"one-api/common"
"strings"
"time"
)
// User if you add sensitive fields, don't forget to clean them in setupLogin function.
@ -202,9 +203,13 @@ func (user *User) Update(updatePassword bool) error {
}
}
newUser := *user
DB.First(&user, user.Id)
err = DB.Model(user).Updates(newUser).Error
if err == nil {
if common.RedisEnabled {
_ = common.RedisSet(fmt.Sprintf("user_group:%d", user.Id), user.Group, time.Duration(UserId2GroupCacheSeconds)*time.Second)
}
}
return err
}