|
@@ -2,11 +2,13 @@ package model
|
|
|
|
|
|
import (
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"jyBXBase/rpc/bxbase"
|
|
|
IC "jyBXBase/rpc/init"
|
|
|
"jyBXBase/rpc/internal/config"
|
|
|
+ "jyBXBase/rpc/util"
|
|
|
"log"
|
|
|
"sort"
|
|
|
"strings"
|
|
@@ -365,49 +367,68 @@ func DataSortInRedis(r *bxbase.NewsetBiddingResp, status int, positionId int64)
|
|
|
// 延长缓存
|
|
|
// 获取最新数据 -- 延长缓存时间7天---待调整: 1、判断是否需要更新;2、判断订阅信息是否存在,如果存在是否是最新推送,3、订阅信息查推送缓存(只有个人版有缓存:pushcache_2_a )
|
|
|
func ExtendNewListCache(n *NewSet, in *bxbase.NewestBiddingReq, list []*bxbase.NewestList) {
|
|
|
- if n.RedisKeyModel.Key != "" {
|
|
|
- now := time.Now()
|
|
|
- if n.RedisKeyModel.CacheUpdateKey != "" {
|
|
|
- var (
|
|
|
- res = &bxbase.NewsetBiddingResp{
|
|
|
- Data: &bxbase.NewsetBidding{
|
|
|
- List: []*bxbase.NewestList{},
|
|
|
- },
|
|
|
- }
|
|
|
- updateTime = redis.GetInt("new", n.RedisKeyModel.CacheUpdateKey)
|
|
|
- )
|
|
|
- switch n.RedisStatus {
|
|
|
- case StatusLoginUser:
|
|
|
- //十五分钟内 更新过一次 不再更新
|
|
|
- if int(now.Unix())-updateTime > n.RedisKeyModel.CacheUpdateTimeout {
|
|
|
- // 登录用户
|
|
|
- roleNewestInfo, _ := GetRoleNewestInfoService(in.AppId, in.MgoUserId, in.NewUserId, in.AccountId, in.EntId, in.EntUserId, in.PositionType, in.PositionId)
|
|
|
- //当前用户有最新推送信息
|
|
|
- lastPublishTime := list[len(list)-1].PublishTime
|
|
|
- if roleNewestInfo.IsHasNewPushData(lastPublishTime) {
|
|
|
- // 查推送
|
|
|
- subscribeTime := time.Now()
|
|
|
- res.Data.List = roleNewestInfo.GetPushHistory()
|
|
|
- log.Println(in.PositionId, "获取订阅数据 存缓存 耗时:", time.Since(subscribeTime).Seconds())
|
|
|
- } else {
|
|
|
- res.Data.List = list
|
|
|
+ if flag := util.ReqLimitInit.Limit(context.Background()); flag != 1 {
|
|
|
+ if flag == -2 {
|
|
|
+ log.Println("等待队列已满")
|
|
|
+ } else if flag == -1 {
|
|
|
+ log.Println("等待超时")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ defer util.ReqLimitInit.Release()
|
|
|
+ if n.RedisKeyModel.Key != "" {
|
|
|
+ now := time.Now()
|
|
|
+ if n.RedisKeyModel.CacheUpdateKey != "" {
|
|
|
+ var (
|
|
|
+ res = &bxbase.NewsetBiddingResp{
|
|
|
+ Data: &bxbase.NewsetBidding{
|
|
|
+ List: []*bxbase.NewestList{},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ updateTime = redis.GetInt("new", n.RedisKeyModel.CacheUpdateKey)
|
|
|
+ isDoing bool
|
|
|
+ )
|
|
|
+ //防止穿透
|
|
|
+ util.ReqLimitLock.Lock()
|
|
|
+ isDoing, _ = redis.Exists("new", fmt.Sprintf("p1_indexMessage_new_recovery_%d", in.PositionId))
|
|
|
+ util.ReqLimitLock.Unlock()
|
|
|
+ if !isDoing {
|
|
|
+ util.ReqLimitLock.Lock()
|
|
|
+ redis.Put("new", fmt.Sprintf("p1_indexMessage_new_recovery_%d", in.PositionId), "1", 15*time.Now().Minute()) //十五分钟
|
|
|
+ util.ReqLimitLock.Unlock()
|
|
|
+ switch n.RedisStatus {
|
|
|
+ case StatusLoginUser:
|
|
|
+ //十五分钟内 更新过一次 不再更新
|
|
|
+ if int(now.Unix())-updateTime > n.RedisKeyModel.CacheUpdateTimeout {
|
|
|
+ // 登录用户
|
|
|
+ roleNewestInfo, _ := GetRoleNewestInfoService(in.AppId, in.MgoUserId, in.NewUserId, in.AccountId, in.EntId, in.EntUserId, in.PositionType, in.PositionId)
|
|
|
+ //当前用户有最新推送信息
|
|
|
+ lastPublishTime := list[len(list)-1].PublishTime
|
|
|
+ if roleNewestInfo.IsHasNewPushData(lastPublishTime) {
|
|
|
+ // 查推送
|
|
|
+ subscribeTime := time.Now()
|
|
|
+ res.Data.List = roleNewestInfo.GetPushHistory()
|
|
|
+ log.Println(in.PositionId, "获取订阅数据 存缓存 耗时:", time.Since(subscribeTime).Seconds())
|
|
|
+ } else {
|
|
|
+ res.Data.List = list
|
|
|
+ }
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ //十五分钟内 更新过一次 不再更新
|
|
|
+ if int(now.Unix())-updateTime > n.RedisKeyModel.CacheUpdateTimeout {
|
|
|
+ res.Data.List = NewestES(n.Query)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(res.Data.List) > 0 {
|
|
|
+ //更新update time
|
|
|
+ redis.Put("new", n.RedisKeyModel.CacheUpdateKey, now.Unix(), n.RedisKeyModel.CacheUpdateTimeout)
|
|
|
+ go DataSortInRedis(res, n.RedisStatus, in.PositionId)
|
|
|
}
|
|
|
}
|
|
|
- default:
|
|
|
- //十五分钟内 更新过一次 不再更新
|
|
|
- if int(now.Unix())-updateTime > n.RedisKeyModel.CacheUpdateTimeout {
|
|
|
- res.Data.List = NewestES(n.Query)
|
|
|
- }
|
|
|
- }
|
|
|
- if len(res.Data.List) > 0 {
|
|
|
- //更新update time
|
|
|
- redis.Put("new", n.RedisKeyModel.CacheUpdateKey, now.Unix(), n.RedisKeyModel.CacheUpdateTimeout)
|
|
|
- go DataSortInRedis(res, n.RedisStatus, in.PositionId)
|
|
|
}
|
|
|
+ ////剩余时间 在 IC.C.NewsTimeOut 之内
|
|
|
+ //if ttl := redis.GetTTL("new", n.RedisKeyModel.Key); ttl-IC.C.NewsTimeOut < 0 {
|
|
|
+ //
|
|
|
+ //}
|
|
|
}
|
|
|
- ////剩余时间 在 IC.C.NewsTimeOut 之内
|
|
|
- //if ttl := redis.GetTTL("new", n.RedisKeyModel.Key); ttl-IC.C.NewsTimeOut < 0 {
|
|
|
- //
|
|
|
- //}
|
|
|
}
|
|
|
}
|