Jelajahi Sumber

feat:最新标讯

wangshan 2 tahun lalu
induk
melakukan
9762f147de
1 mengubah file dengan 18 tambahan dan 1 penghapusan
  1. 18 1
      jyBXBase/rpc/model/newestBidding.go

+ 18 - 1
jyBXBase/rpc/model/newestBidding.go

@@ -1,6 +1,7 @@
 package model
 
 import (
+	"app.yhyue.com/moapp/jybase/redis"
 	"fmt"
 	"jyBXBase/rpc/bxbase"
 	IC "jyBXBase/rpc/init"
@@ -54,6 +55,22 @@ func GetNewestInfo(userId, userType string, newUserId int64) *NewestInfo {
 	}
 	return nt
 }
+
+// 缓存code  配置最新的redis code;可以感觉redis内存大小 调节redis存储
+func (n *NewestInfo) GetPushHistoryCount() int64 {
+	countKey := fmt.Sprintf("push_count_%s_%s", n.TableName, n.UserId)
+	if b := redis.GetInt("other", countKey); b > 0 {
+		return int64(b)
+	}
+	countSql := "select count(1) from %s  a  where a.userid=%d order by a.id desc"
+	countSql = fmt.Sprintf(countSql, n.TableName, n.NewUserId)
+	if c := n.MysqlDb.CountBySql(countSql); c > 0 {
+		redis.Put("other", countKey, c, 60) //过期时间走配置,比最新标讯列表缓存时间 要短1/10 尽量不超过两分钟
+		return c
+	}
+	return 0
+}
+
 func (n *NewestInfo) GetPushHistory() (res []*bxbase.NewestList) {
 	findSQL := "select a.infoid,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.attachment_count,a.budget,a.bidamount from %s  a  where a.userid=%d and a.date>=%d  order by a.id desc limit 50"
 	findSQL = fmt.Sprintf(findSQL, n.TableName, n.NewUserId, time.Now().AddDate(0, 0, -7).Unix())
@@ -73,7 +90,7 @@ func (n *NewestInfo) GetPushHistory() (res []*bxbase.NewestList) {
 			//
 			infos[infoId] = &bxbase.NewestList{
 				Id:         ME.EncodeArticleId2ByCheck(MC.ObjToString(v["infoid"])),
-				Matchkeys:  strings.Split(MC.ObjToString(v["matchkeys"])," "),
+				Matchkeys:  strings.Split(MC.ObjToString(v["matchkeys"]), " "),
 				Budget:     MC.Int64All(v["budget"]),
 				Bidamount:  MC.Int64All(v["bidamount"]),
 				FileExists: MC.Int64All(v["attachment_count"]) > 0,