瀏覽代碼

更新用户时刷新缓存数据

CaIon 2 年之前
父節點
當前提交
7e4fe14871
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      model/user.go

+ 6 - 1
model/user.go

@@ -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
 }