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
512aa032
Commit
512aa032
authored
Jul 24, 2023
by
iamhujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bannedGroupCache
parent
32dff1b1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
groupBanned.go
domain/model/group_m/groupBanned.go
+10
-0
No files found.
domain/model/group_m/groupBanned.go
View file @
512aa032
...
...
@@ -3,6 +3,8 @@ package group_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/bluele/gcache"
"time"
)
type
GroupBanned
struct
{
...
...
@@ -24,12 +26,20 @@ func (banned *GroupBanned) Delete(model *domain.Model) error {
return
model
.
Db
.
Where
(
banned
)
.
Delete
(
&
GroupBanned
{})
.
Error
}
var
bannedGroupCache
=
gcache
.
New
(
100
)
.
LRU
()
.
Build
()
func
GetBannedGroups
(
model
*
domain
.
Model
)
([]
GroupBanned
,
error
)
{
key
:=
"banned"
if
data
,
err
:=
bannedGroupCache
.
Get
(
key
);
err
==
nil
{
model
.
Log
.
Infof
(
"GetBannedGroups cache:%v"
,
len
(
data
.
([]
GroupBanned
)))
return
data
.
([]
GroupBanned
),
nil
}
result
:=
make
([]
GroupBanned
,
0
)
err
:=
model
.
Db
.
Find
(
&
result
)
.
Error
if
err
!=
nil
{
return
nil
,
err
}
bannedGroupCache
.
SetWithExpire
(
key
,
result
,
time
.
Minute
*
5
)
return
result
,
nil
}
...
...
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