Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
8b61f804
Commit
8b61f804
authored
Aug 31, 2023
by
iamhujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
medal lru
parent
96b54e85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
62 deletions
+13
-62
cache_medal.go
domain/model/common/cache_medal.go
+11
-60
medal.go
domain/model/user_m/medal.go
+2
-2
No files found.
domain/model/common/cache_medal.go
View file @
8b61f804
package
common
package
common
import
(
import
(
"context"
"encoding/json"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/utils"
"git.hilo.cn/hilo-common/utils"
"hilo-group/_const/redis_key"
"github.com/bluele/gcache"
"hilo-group/myerr"
"time"
"time"
)
)
func
GetUserMedalMergeCache
(
userId
mysql
.
ID
)
([]
uint32
,
error
)
{
// 改成lru
bData
,
err
:=
GetCache
(
redis_key
.
GetUserMedalMerge
(
userId
))
var
userMedalMergeLru
=
gcache
.
New
(
10000
)
.
LRU
()
.
Build
()
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
res
:=
make
([]
uint32
,
0
)
func
GetUserMedalMergeCache
(
userId
mysql
.
ID
)
([]
uint32
,
error
)
{
err
=
json
.
Unmarshal
(
bData
,
&
res
)
if
data
,
err
:=
userMedalMergeLru
.
Get
(
userId
);
err
==
nil
{
if
err
!=
nil
{
return
data
.
([]
uint32
),
nil
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
return
res
,
nil
return
nil
,
nil
}
}
func
SetUserMedalMergeCache
(
userId
mysql
.
ID
,
data
[]
uint32
)
error
{
func
SetUserMedalMergeCache
(
userId
mysql
.
ID
,
data
[]
uint32
)
{
err
:=
SetCache
(
redis_key
.
GetUserMedalMerge
(
userId
),
data
,
time
.
Hour
*
2
)
_
=
userMedalMergeLru
.
SetWithExpire
(
userId
,
data
,
time
.
Minute
*
15
)
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"SetUserMedalMerge err:%s"
,
err
)
return
myerr
.
WrapErr
(
err
)
}
return
nil
}
}
// 删除勋章缓存, 延迟删除
// 删除勋章缓存, 延迟删除
...
@@ -44,41 +30,6 @@ func DelUserMedalMergeCacheDelay(userId mysql.ID) {
...
@@ -44,41 +30,6 @@ func DelUserMedalMergeCacheDelay(userId mysql.ID) {
}()
}()
}
}
func
DelUserMedalMergeCache
(
userId
mysql
.
ID
)
error
{
func
DelUserMedalMergeCache
(
userId
mysql
.
ID
)
{
err
:=
DelCache
(
redis_key
.
GetUserMedalMerge
(
userId
))
userMedalMergeLru
.
Remove
(
userId
)
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"DetUserMedalMerge err:%s, userId:%v"
,
err
,
userId
)
return
myerr
.
WrapErr
(
err
)
}
return
nil
}
func
DelCache
(
key
string
)
error
{
err
:=
redisCli
.
GetRedis
()
.
Del
(
context
.
Background
(),
key
)
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"DelCache key:%s, err:%s"
,
key
,
err
)
return
err
}
return
nil
}
func
GetCache
(
key
string
)
([]
byte
,
error
)
{
data
,
err
:=
redisCli
.
GetRedis
()
.
Get
(
context
.
Background
(),
key
)
.
Bytes
()
if
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
}
func
SetCache
(
key
string
,
data
interface
{},
expire
time
.
Duration
)
error
{
jData
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
return
err
}
err
=
redisCli
.
GetRedis
()
.
Set
(
context
.
Background
(),
key
,
jData
,
expire
)
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"SetCache key:%s, data:%v, err:%s"
,
key
,
data
,
err
)
return
err
}
return
nil
}
}
domain/model/user_m/medal.go
View file @
8b61f804
...
@@ -70,8 +70,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui
...
@@ -70,8 +70,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui
}
}
}
}
}
}
logger
.
Infof
(
"maxGrade %+v"
,
maxGrades
)
//
logger.Infof("maxGrade %+v", maxGrades)
logger
.
Infof
(
"maxMedalIds %+v"
,
maxMedalIds
)
//
logger.Infof("maxMedalIds %+v", maxMedalIds)
mIds
:=
result
mIds
:=
result
result
=
make
([]
uint32
,
0
)
result
=
make
([]
uint32
,
0
)
...
...
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