CalciumIon 1 год назад
Родитель
Сommit
b4f17543cb
2 измененных файлов с 21 добавлено и 17 удалено
  1. 20 16
      model/token.go
  2. 1 1
      web/src/helpers/render.js

+ 20 - 16
model/token.go

@@ -133,7 +133,7 @@ func GetTokenById(id int) (*Token, error) {
 	token := Token{Id: id}
 	var err error = nil
 	err = DB.First(&token, "id = ?", id).Error
-	if err != nil {
+	if shouldUpdateRedis(true, err) {
 		gopool.Go(func() {
 			if err := cacheSetToken(token); err != nil {
 				common.SysError("failed to update user status cache: " + err.Error())
@@ -176,7 +176,7 @@ func (token *Token) Insert() error {
 // Update Make sure your token's fields is completed, because this will update non-zero values
 func (token *Token) Update() (err error) {
 	defer func() {
-		if common.RedisEnabled && err == nil {
+		if shouldUpdateRedis(true, err) {
 			gopool.Go(func() {
 				err := cacheSetToken(*token)
 				if err != nil {
@@ -192,7 +192,7 @@ func (token *Token) Update() (err error) {
 
 func (token *Token) SelectUpdate() (err error) {
 	defer func() {
-		if common.RedisEnabled && err == nil {
+		if shouldUpdateRedis(true, err) {
 			gopool.Go(func() {
 				err := cacheSetToken(*token)
 				if err != nil {
@@ -207,7 +207,7 @@ func (token *Token) SelectUpdate() (err error) {
 
 func (token *Token) Delete() (err error) {
 	defer func() {
-		if common.RedisEnabled && err == nil {
+		if shouldUpdateRedis(true, err) {
 			gopool.Go(func() {
 				err := cacheDeleteToken(token.Key)
 				if err != nil {
@@ -267,12 +267,14 @@ func IncreaseTokenQuota(id int, key string, quota int) (err error) {
 	if quota < 0 {
 		return errors.New("quota 不能为负数!")
 	}
-	gopool.Go(func() {
-		err := cacheIncrTokenQuota(key, int64(quota))
-		if err != nil {
-			common.SysError("failed to increase token quota: " + err.Error())
-		}
-	})
+	if common.RedisEnabled {
+		gopool.Go(func() {
+			err := cacheIncrTokenQuota(key, int64(quota))
+			if err != nil {
+				common.SysError("failed to increase token quota: " + err.Error())
+			}
+		})
+	}
 	if common.BatchUpdateEnabled {
 		addNewRecord(BatchUpdateTypeTokenQuota, id, quota)
 		return nil
@@ -295,12 +297,14 @@ func DecreaseTokenQuota(id int, key string, quota int) (err error) {
 	if quota < 0 {
 		return errors.New("quota 不能为负数!")
 	}
-	gopool.Go(func() {
-		err := cacheDecrTokenQuota(key, int64(quota))
-		if err != nil {
-			common.SysError("failed to decrease token quota: " + err.Error())
-		}
-	})
+	if common.RedisEnabled {
+		gopool.Go(func() {
+			err := cacheDecrTokenQuota(key, int64(quota))
+			if err != nil {
+				common.SysError("failed to decrease token quota: " + err.Error())
+			}
+		})
+	}
 	if common.BatchUpdateEnabled {
 		addNewRecord(BatchUpdateTypeTokenQuota, id, -quota)
 		return nil

+ 1 - 1
web/src/helpers/render.js

@@ -64,7 +64,7 @@ export function renderRatio(ratio) {
   } else if (ratio > 1) {
     color = 'blue';
   }
-  return <Tag color={color}>{ratio} {i18next.t('倍率')}</Tag>;
+  return <Tag color={color}>{ratio}x {i18next.t('倍率')}</Tag>;
 }
 
 export const renderGroupOption = (item) => {