Skip to content

Commit

Permalink
fix redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Dec 30, 2024
1 parent 1eb706d commit b4f1754
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 20 additions & 16 deletions model/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/src/helpers/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit b4f1754

Please sign in to comment.