Authored by 周少峰

Merge branch 'hotfix/add-cache' into gray

... ... @@ -10,11 +10,13 @@ const redis = global.yoho.redis;
const cache = global.yoho.cache;
const logger = global.yoho.logger;
const uuid = require('uuid');
const helpers = global.yoho.helpers;
const _ = require('lodash');
function _cacheGet(key) {
return cache.get(key).then((data) => {
if (data) {
return data;
return JSON.parse(data);
}
return Promise.reject();
... ... @@ -195,10 +197,25 @@ const getLikeAsync = (skn, limit) => {
}, {cache: 86400});
};
// 返回6条推荐关键词页面
function getKeywordsInfo(keywords) {
let res = [];
_.forEach(_.slice(_.shuffle(keywords), 0, 12), val => {
res.push({
url: helpers.urlFormat(`/chanpin/${val.id}.html`),
keyword: val.keyword
});
});
return res;
}
// 根据small_sort从redis获取分类下的关键词
function _getRecommendKeywords(smallSort) {
return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => {
return res[0];
}).then(result => {
return getKeywordsInfo(JSON.parse(result || '[]'));
});
}
... ...
... ... @@ -36,7 +36,6 @@ const BUNDLE_PRODUCE = 2; // 量贩
const BUNDLE_PACKAGE = 1; // 套餐
const tdk = require('../../../utils/getTDK');
const productProcess = require('../../../utils/product-process');
const Helpers = global.yoho.helpers;
const _getProductAdditionInfoAsync = (data) => {
return co(function * () {
... ... @@ -1010,19 +1009,6 @@ const _getIntroInfo = (productSkn, maxSortId, additionalData)=> {
return result;
};
// 返回6条推荐关键词页面
const getKeywordsInfo = (keywords) => {
let res = [];
_.forEach(_.slice(_.shuffle(keywords), 0, 12), val => {
res.push({
url: Helpers.urlFormat(`/chanpin/${val.id}.html`),
keyword: val.keyword
});
});
return res;
};
/**
* 获取seo信息
*
... ... @@ -1194,13 +1180,12 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
let coupon = requestData.coupon;
let limitedInfo = requestData.limited;
let bundle = requestData.bundle;
let recommendKeywords = requestData.recommendKeywords ? JSON.parse(requestData.recommendKeywords) : [];
// 处理相似商品
result.alike = productProcess.processProductList(_.get(requestData, 'alike.data.product_list', ''));
// 推荐关键词页面
result.recommendKeywords = getKeywordsInfo(recommendKeywords);
result.recommendKeywords = requestData.recommendKeywords;
// 处理店铺推荐
result.shopRecommend = productProcess.processProductList(
... ...