Commit c08701f9 authored by hujiebin's avatar hujiebin

同步送礼推荐用户,多进程都需要执行

parent 0fc2905e
......@@ -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
}
......
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()
}
......@@ -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{}
}
// 榜单黑名单
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment