Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2de4de00
authored
Dec 30, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix redis
parent
3514287e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
model/token.go
+8
-4
web/src/helpers/render.js
+1
-1
No files found.
model/token.go
View file @
2de4de00
...
...
@@ -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 不能为负数!"
)
}
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 不能为负数!"
)
}
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
...
...
web/src/helpers/render.js
View file @
2de4de00
...
...
@@ -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
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment