Authored by 周少峰

Merge branch 'hotfix/add-cache' into gray

@@ -10,11 +10,13 @@ const redis = global.yoho.redis; @@ -10,11 +10,13 @@ const redis = global.yoho.redis;
10 const cache = global.yoho.cache; 10 const cache = global.yoho.cache;
11 const logger = global.yoho.logger; 11 const logger = global.yoho.logger;
12 const uuid = require('uuid'); 12 const uuid = require('uuid');
  13 +const helpers = global.yoho.helpers;
  14 +const _ = require('lodash');
13 15
14 function _cacheGet(key) { 16 function _cacheGet(key) {
15 return cache.get(key).then((data) => { 17 return cache.get(key).then((data) => {
16 if (data) { 18 if (data) {
17 - return data; 19 + return JSON.parse(data);
18 } 20 }
19 21
20 return Promise.reject(); 22 return Promise.reject();
@@ -195,10 +197,25 @@ const getLikeAsync = (skn, limit) => { @@ -195,10 +197,25 @@ const getLikeAsync = (skn, limit) => {
195 }, {cache: 86400}); 197 }, {cache: 86400});
196 }; 198 };
197 199
  200 +// 返回6条推荐关键词页面
  201 +function getKeywordsInfo(keywords) {
  202 + let res = [];
  203 +
  204 + _.forEach(_.slice(_.shuffle(keywords), 0, 12), val => {
  205 + res.push({
  206 + url: helpers.urlFormat(`/chanpin/${val.id}.html`),
  207 + keyword: val.keyword
  208 + });
  209 + });
  210 + return res;
  211 +}
  212 +
198 // 根据small_sort从redis获取分类下的关键词 213 // 根据small_sort从redis获取分类下的关键词
199 function _getRecommendKeywords(smallSort) { 214 function _getRecommendKeywords(smallSort) {
200 return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => { 215 return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => {
201 return res[0]; 216 return res[0];
  217 + }).then(result => {
  218 + return getKeywordsInfo(JSON.parse(result || '[]'));
202 }); 219 });
203 } 220 }
204 221
@@ -36,7 +36,6 @@ const BUNDLE_PRODUCE = 2; // 量贩 @@ -36,7 +36,6 @@ const BUNDLE_PRODUCE = 2; // 量贩
36 const BUNDLE_PACKAGE = 1; // 套餐 36 const BUNDLE_PACKAGE = 1; // 套餐
37 const tdk = require('../../../utils/getTDK'); 37 const tdk = require('../../../utils/getTDK');
38 const productProcess = require('../../../utils/product-process'); 38 const productProcess = require('../../../utils/product-process');
39 -const Helpers = global.yoho.helpers;  
40 39
41 const _getProductAdditionInfoAsync = (data) => { 40 const _getProductAdditionInfoAsync = (data) => {
42 return co(function * () { 41 return co(function * () {
@@ -1010,19 +1009,6 @@ const _getIntroInfo = (productSkn, maxSortId, additionalData)=> { @@ -1010,19 +1009,6 @@ const _getIntroInfo = (productSkn, maxSortId, additionalData)=> {
1010 return result; 1009 return result;
1011 }; 1010 };
1012 1011
1013 -// 返回6条推荐关键词页面  
1014 -const getKeywordsInfo = (keywords) => {  
1015 - let res = [];  
1016 -  
1017 - _.forEach(_.slice(_.shuffle(keywords), 0, 12), val => {  
1018 - res.push({  
1019 - url: Helpers.urlFormat(`/chanpin/${val.id}.html`),  
1020 - keyword: val.keyword  
1021 - });  
1022 - });  
1023 - return res;  
1024 -};  
1025 -  
1026 /** 1012 /**
1027 * 获取seo信息 1013 * 获取seo信息
1028 * 1014 *
@@ -1194,13 +1180,12 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => { @@ -1194,13 +1180,12 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
1194 let coupon = requestData.coupon; 1180 let coupon = requestData.coupon;
1195 let limitedInfo = requestData.limited; 1181 let limitedInfo = requestData.limited;
1196 let bundle = requestData.bundle; 1182 let bundle = requestData.bundle;
1197 - let recommendKeywords = requestData.recommendKeywords ? JSON.parse(requestData.recommendKeywords) : [];  
1198 1183
1199 // 处理相似商品 1184 // 处理相似商品
1200 result.alike = productProcess.processProductList(_.get(requestData, 'alike.data.product_list', '')); 1185 result.alike = productProcess.processProductList(_.get(requestData, 'alike.data.product_list', ''));
1201 1186
1202 // 推荐关键词页面 1187 // 推荐关键词页面
1203 - result.recommendKeywords = getKeywordsInfo(recommendKeywords); 1188 + result.recommendKeywords = requestData.recommendKeywords;
1204 1189
1205 // 处理店铺推荐 1190 // 处理店铺推荐
1206 result.shopRecommend = productProcess.processProductList( 1191 result.shopRecommend = productProcess.processProductList(