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
b26e53bc
authored
Apr 18, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update cache
parent
92ad9eb1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
6 deletions
+3
-6
model/cache.go
+2
-5
model/user.go
+1
-1
No files found.
model/cache.go
View file @
b26e53bc
...
@@ -25,9 +25,6 @@ var token2UserId = make(map[string]int)
...
@@ -25,9 +25,6 @@ var token2UserId = make(map[string]int)
var
token2UserIdLock
sync
.
RWMutex
var
token2UserIdLock
sync
.
RWMutex
func
cacheSetToken
(
token
*
Token
)
error
{
func
cacheSetToken
(
token
*
Token
)
error
{
if
!
common
.
RedisEnabled
{
return
token
.
SelectUpdate
()
}
jsonBytes
,
err
:=
json
.
Marshal
(
token
)
jsonBytes
,
err
:=
json
.
Marshal
(
token
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -168,10 +165,10 @@ func CacheUpdateUserQuota(id int) error {
...
@@ -168,10 +165,10 @@ func CacheUpdateUserQuota(id int) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
C
acheSetUserQuota
(
id
,
quota
)
return
c
acheSetUserQuota
(
id
,
quota
)
}
}
func
C
acheSetUserQuota
(
id
int
,
quota
int
)
error
{
func
c
acheSetUserQuota
(
id
int
,
quota
int
)
error
{
err
:=
common
.
RedisSet
(
fmt
.
Sprintf
(
"user_quota:%d"
,
id
),
fmt
.
Sprintf
(
"%d"
,
quota
),
time
.
Duration
(
UserId2QuotaCacheSeconds
)
*
time
.
Second
)
err
:=
common
.
RedisSet
(
fmt
.
Sprintf
(
"user_quota:%d"
,
id
),
fmt
.
Sprintf
(
"%d"
,
quota
),
time
.
Duration
(
UserId2QuotaCacheSeconds
)
*
time
.
Second
)
return
err
return
err
}
}
...
...
model/user.go
View file @
b26e53bc
...
@@ -412,7 +412,7 @@ func GetUserQuota(id int) (quota int, err error) {
...
@@ -412,7 +412,7 @@ func GetUserQuota(id int) (quota int, err error) {
err
=
DB
.
Model
(
&
User
{})
.
Where
(
"id = ?"
,
id
)
.
Select
(
"quota"
)
.
Find
(
&
quota
)
.
Error
err
=
DB
.
Model
(
&
User
{})
.
Where
(
"id = ?"
,
id
)
.
Select
(
"quota"
)
.
Find
(
&
quota
)
.
Error
if
err
!=
nil
{
if
err
!=
nil
{
if
common
.
RedisEnabled
{
if
common
.
RedisEnabled
{
go
C
acheSetUserQuota
(
id
,
quota
)
go
c
acheSetUserQuota
(
id
,
quota
)
}
}
}
}
return
quota
,
err
return
quota
,
err
...
...
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