|
@@ -477,9 +477,10 @@ func (p *Purchase) FindDataFromES() (int64, []map[string]interface{}, error) {
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
- redisCode = "newother"
|
|
|
- purchaseCacheKey = "purchase_cache_data"
|
|
|
- purchaseCacheExpire = 4 * 60 * 60
|
|
|
+ redisCode = "newother"
|
|
|
+ purchaseDataCacheKey = "purchase_cache_data"
|
|
|
+ purchaseCountCacheKey = "purchase_cache_count"
|
|
|
+ purchaseCacheExpire = 8 * 60 * 60
|
|
|
)
|
|
|
|
|
|
func (p *Purchase) GetPurchaseData() (list []*bxcore.PurchaseList, err error) {
|
|
@@ -489,38 +490,36 @@ func (p *Purchase) GetPurchaseData() (list []*bxcore.PurchaseList, err error) {
|
|
|
)
|
|
|
if p.IsEmptySearch() {
|
|
|
//查缓存
|
|
|
- cacheBytes, err := redis.GetBytes(redisCode, purchaseCacheKey)
|
|
|
+ cacheBytes, err := redis.GetBytes(redisCode, purchaseDataCacheKey)
|
|
|
start := int((p.PageNum - 1) * p.PageSize)
|
|
|
+ end := int(p.PageNum * p.PageSize)
|
|
|
if err == nil && len(*cacheBytes) > start {
|
|
|
- end := int(p.PageNum * p.PageSize)
|
|
|
if end > len(*cacheBytes) {
|
|
|
end = len(*cacheBytes)
|
|
|
}
|
|
|
- total = int64(len(*cacheBytes))
|
|
|
- err = json.Unmarshal((*cacheBytes)[start:end], &res)
|
|
|
+ total = int64(redis.GetInt(redisCode, purchaseCountCacheKey))
|
|
|
+ err = json.Unmarshal(*cacheBytes, &res)
|
|
|
}
|
|
|
if len(res) == 0 {
|
|
|
p.PageNum = 1
|
|
|
pageSize := p.PageSize
|
|
|
start = int((p.PageNum - 1) * p.PageSize)
|
|
|
- end := int(p.PageNum * p.PageSize)
|
|
|
p.PageSize = int64(util.SearchPageSize * util.SearchMaxPageNum)
|
|
|
total, res, err = p.FindDataFromES()
|
|
|
- log.Println(total, "----------缓存数据:", len(res))
|
|
|
if total > 0 && len(res) > 0 {
|
|
|
var b []byte
|
|
|
b, err = json.Marshal(res)
|
|
|
- log.Println(b, "----------------002---------------------", err)
|
|
|
if err == nil && len(b) > 0 {
|
|
|
- err = redis.PutBytes(redisCode, purchaseCacheKey, &b, purchaseCacheExpire)
|
|
|
+ err = redis.PutBytes(redisCode, purchaseDataCacheKey, &b, purchaseCacheExpire)
|
|
|
+ redis.Put(redisCode, purchaseCountCacheKey, total, purchaseCacheExpire)
|
|
|
}
|
|
|
if end > len(res) {
|
|
|
end = len(res)
|
|
|
}
|
|
|
- res = res[start:end]
|
|
|
}
|
|
|
p.PageSize = pageSize
|
|
|
}
|
|
|
+ res = res[start:end]
|
|
|
} else {
|
|
|
//实时查询
|
|
|
total, res, err = p.FindDataFromES()
|