From b4f17543cb0267245285fac234e8ea8aedbba1fe Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Mon, 30 Dec 2024 22:05:41 +0800 Subject: [PATCH] fix redis --- model/token.go | 36 ++++++++++++++++++++---------------- web/src/helpers/render.js | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/model/token.go b/model/token.go index 1596a8ddd..39bea5364 100644 --- a/model/token.go +++ b/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 diff --git a/web/src/helpers/render.js b/web/src/helpers/render.js index 9193f6447..85ff3ed4f 100644 --- a/web/src/helpers/render.js +++ b/web/src/helpers/render.js @@ -64,7 +64,7 @@ export function renderRatio(ratio) { } else if (ratio > 1) { color = 'blue'; } - return {ratio} {i18next.t('倍率')}; + return {ratio}x {i18next.t('倍率')}; } export const renderGroupOption = (item) => {