Commit 089ef3c9 authored by chenweijian's avatar chenweijian

Merge remote-tracking branch 'origin/master' into feature/4.3_cwj

parents 5a3b75bb c08701f9
...@@ -4,9 +4,11 @@ import ( ...@@ -4,9 +4,11 @@ import (
"git.hilo.cn/hilo-common/resource/config" "git.hilo.cn/hilo-common/resource/config"
"hilo-user/cron/cp_cron" "hilo-user/cron/cp_cron"
"hilo-user/cron/gift_cron" "hilo-user/cron/gift_cron"
"hilo-user/cron/user_cron"
) )
func Init() { func Init() {
user_cron.SyncGiftRecommendUsers() // 同步送礼推荐用户,多进程都需要执行
if !config.IsMaster() { if !config.IsMaster() {
return 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" ...@@ -17,12 +17,7 @@ var recommendUserGiftKey = "recommendUserGiftKey"
var recommendUserGiftCache = gcache.New(1).LRU().Build() var recommendUserGiftCache = gcache.New(1).LRU().Build()
// 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户 // 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户
// 先lru cache,后db func SyncPastTop50SendGiftUsers(model *domain.Model) {
// ttl: 5min
func GetPastTop50SendGiftUsers(model *domain.Model) []recommendUserGift {
if data, err := recommendUserGiftCache.Get(recommendUserGiftKey); err == nil {
return data.([]recommendUserGift)
}
limitUserIds, _ := GetBillboardLimitUserList(model) limitUserIds, _ := GetBillboardLimitUserList(model)
var res []recommendUserGift 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"). 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 { ...@@ -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 { Having("send_user_diamond > 100000").Order("send_user_diamond DESC").Limit(34).Find(&res).Error; err != nil {
model.Log.Errorf("GetPastTop50SendGiftUsers fail:%v", err) model.Log.Errorf("GetPastTop50SendGiftUsers fail:%v", err)
} }
recommendUserGiftCache.SetWithExpire(recommendUserGiftKey, res, time.Minute*5) _ = recommendUserGiftCache.Set(recommendUserGiftKey, res)
return res }
// 只从缓存中拿
func GetPastTop50SendGiftUsers(model *domain.Model) []recommendUserGift {
if data, err := recommendUserGiftCache.Get(recommendUserGiftKey); err == nil {
return data.([]recommendUserGift)
}
return []recommendUserGift{}
} }
// 榜单黑名单 // 榜单黑名单
......
[DATABASE] [DATABASE]
MYSQL_HOST=ua4papc3hmgqf351pbej-rw4rm.rwlb.dubai.rds.aliyuncs.com MYSQL_HOST=ua4papc3hmgqf351pbej-rw4rm.rwlb.dubai.rds.aliyuncs.com
MYSQL_USERNAME=nextvideo MYSQL_USERNAME=hilo_user
MYSQL_PASSWORD=ihlUwI4nhi9W88MI MYSQL_PASSWORD=ihlUwI4nhi9W88MI
MYSQL_DB=hilo MYSQL_DB=hilo
[DATABASECODE] [DATABASECODE]
......
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