Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-user
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
chenweijian
hilo-user
Commits
c08701f9
Commit
c08701f9
authored
Jul 27, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步送礼推荐用户,多进程都需要执行
parent
0fc2905e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
+32
-8
cron.go
cron/cron.go
+2
-0
gift_user.go
cron/user_cron/gift_user.go
+20
-0
gift.go
domain/model/recommend_m/gift.go
+10
-8
No files found.
cron/cron.go
View file @
c08701f9
...
...
@@ -4,9 +4,11 @@ import (
"git.hilo.cn/hilo-common/resource/config"
"hilo-user/cron/cp_cron"
"hilo-user/cron/gift_cron"
"hilo-user/cron/user_cron"
)
func
Init
()
{
user_cron
.
SyncGiftRecommendUsers
()
// 同步送礼推荐用户,多进程都需要执行
if
!
config
.
IsMaster
()
{
return
}
...
...
cron/user_cron/gift_user.go
0 → 100644
View file @
c08701f9
package
user_cron
import
(
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-user/domain/model/recommend_m"
)
// 定期同步礼物推荐用户
func
SyncGiftRecommendUsers
()
{
go
recommend_m
.
SyncPastTop50SendGiftUsers
(
domain
.
CreateModelNil
())
// 启动先同步一次
c
:=
cron
.
New
()
spec
:=
"0 */5 * * * ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
recommend_m
.
SyncPastTop50SendGiftUsers
(
model
)
})
c
.
Start
()
}
domain/model/recommend_m/gift.go
View file @
c08701f9
...
...
@@ -17,12 +17,7 @@ var recommendUserGiftKey = "recommendUserGiftKey"
var
recommendUserGiftCache
=
gcache
.
New
(
1
)
.
LRU
()
.
Build
()
// 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户
// 先lru cache,后db
// ttl: 5min
func
GetPastTop50SendGiftUsers
(
model
*
domain
.
Model
)
[]
recommendUserGift
{
if
data
,
err
:=
recommendUserGiftCache
.
Get
(
recommendUserGiftKey
);
err
==
nil
{
return
data
.
([]
recommendUserGift
)
}
func
SyncPastTop50SendGiftUsers
(
model
*
domain
.
Model
)
{
limitUserIds
,
_
:=
GetBillboardLimitUserList
(
model
)
var
res
[]
recommendUserGift
if
err
:=
model
.
DB
()
.
Table
(
"gift_operate g"
)
.
Joins
(
"INNER JOIN user u ON u.id = g.send_user_id"
)
.
Select
(
"send_user_id,SUM(send_user_diamond) send_user_diamond"
)
.
...
...
@@ -33,8 +28,15 @@ func GetPastTop50SendGiftUsers(model *domain.Model) []recommendUserGift {
Having
(
"send_user_diamond > 100000"
)
.
Order
(
"send_user_diamond DESC"
)
.
Limit
(
34
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetPastTop50SendGiftUsers fail:%v"
,
err
)
}
recommendUserGiftCache
.
SetWithExpire
(
recommendUserGiftKey
,
res
,
time
.
Minute
*
5
)
return
res
_
=
recommendUserGiftCache
.
Set
(
recommendUserGiftKey
,
res
)
}
// 只从缓存中拿
func
GetPastTop50SendGiftUsers
(
model
*
domain
.
Model
)
[]
recommendUserGift
{
if
data
,
err
:=
recommendUserGiftCache
.
Get
(
recommendUserGiftKey
);
err
==
nil
{
return
data
.
([]
recommendUserGift
)
}
return
[]
recommendUserGift
{}
}
// 榜单黑名单
...
...
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