Merge branch 'hotfix/add-cache' into feature/detail-op
# Conflicts: # apps/product/models/detail-product-api.js # apps/product/models/detail-service.js
Showing
2 changed files
with
20 additions
and
17 deletions
@@ -8,11 +8,12 @@ const config = global.yoho.config; | @@ -8,11 +8,12 @@ const config = global.yoho.config; | ||
8 | const redis = global.yoho.redis; | 8 | const redis = global.yoho.redis; |
9 | const cache = global.yoho.cache; | 9 | const cache = global.yoho.cache; |
10 | const logger = global.yoho.logger; | 10 | const logger = global.yoho.logger; |
11 | +const helpers = global.yoho.helpers; | ||
12 | +const _ = require('lodash'); | ||
11 | 13 | ||
12 | const SearchServiceModel = require('./search-api'); | 14 | const SearchServiceModel = require('./search-api'); |
13 | const GuangServiceModel = require('../../guang/models/guang-service'); | 15 | const GuangServiceModel = require('../../guang/models/guang-service'); |
14 | const productProcess = require('../../../utils/product-process'); | 16 | const productProcess = require('../../../utils/product-process'); |
15 | -const _ = require('lodash'); | ||
16 | const uuid = require('uuid'); | 17 | const uuid = require('uuid'); |
17 | 18 | ||
18 | function _cacheGet(key) { | 19 | function _cacheGet(key) { |
@@ -34,7 +35,7 @@ function _cacheSave(key, value) { | @@ -34,7 +35,7 @@ function _cacheSave(key, value) { | ||
34 | } | 35 | } |
35 | 36 | ||
36 | function _cached(fn, ctx) { | 37 | function _cached(fn, ctx) { |
37 | - const pre = (fn.name || 'random:' + uuid.v4()) + ':'; | 38 | + const pre = 'recommend-cache:' + (fn.name || 'random:' + uuid.v4()) + ':'; |
38 | 39 | ||
39 | return function() { | 40 | return function() { |
40 | const args = Array.prototype.slice.call(arguments); | 41 | const args = Array.prototype.slice.call(arguments); |
@@ -252,7 +253,22 @@ module.exports = class extends global.yoho.BaseModel { | @@ -252,7 +253,22 @@ module.exports = class extends global.yoho.BaseModel { | ||
252 | getRecommendKeywords(smallSort) { | 253 | getRecommendKeywords(smallSort) { |
253 | return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => { | 254 | return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => { |
254 | return res[0]; | 255 | return res[0]; |
256 | + }).then(result => { | ||
257 | + return this._getKeywordsInfo(JSON.parse(result || '[]')); | ||
258 | + }) | ||
259 | + } | ||
260 | + | ||
261 | + // 返回6条推荐关键词页面 | ||
262 | + _getKeywordsInfo(keywords) { | ||
263 | + let res = []; | ||
264 | + | ||
265 | + _.forEach(_.slice(_.shuffle(keywords), 0, 12), val => { | ||
266 | + res.push({ | ||
267 | + url: helpers.urlFormat(`/chanpin/${val.id}.html`), | ||
268 | + keyword: val.keyword | ||
269 | + }); | ||
255 | }); | 270 | }); |
271 | + return res; | ||
256 | } | 272 | } |
257 | 273 | ||
258 | _getNewProduct(sort) { | 274 | _getNewProduct(sort) { |
@@ -925,19 +925,6 @@ function _getIntroInfo(productSkn, maxSortId, additionalData) { | @@ -925,19 +925,6 @@ function _getIntroInfo(productSkn, maxSortId, additionalData) { | ||
925 | return result; | 925 | return result; |
926 | } | 926 | } |
927 | 927 | ||
928 | -// 返回6条推荐关键词页面 | ||
929 | -function getKeywordsInfo(keywords) { | ||
930 | - let res = []; | ||
931 | - | ||
932 | - _.forEach(_.slice(_.shuffle(keywords), 0, 12), val => { | ||
933 | - res.push({ | ||
934 | - url: helpers.urlFormat(`/chanpin/${val.id}.html`), | ||
935 | - keyword: val.keyword | ||
936 | - }); | ||
937 | - }); | ||
938 | - return res; | ||
939 | -} | ||
940 | - | ||
941 | /** | 928 | /** |
942 | * 获取seo信息 | 929 | * 获取seo信息 |
943 | * | 930 | * |
@@ -1115,7 +1102,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) { | @@ -1115,7 +1102,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) { | ||
1115 | let coupon = requestData.coupon; | 1102 | let coupon = requestData.coupon; |
1116 | let limitedInfo = requestData.limited; | 1103 | let limitedInfo = requestData.limited; |
1117 | let bundle = requestData.bundle; | 1104 | let bundle = requestData.bundle; |
1118 | - let recommendKeywords = JSON.parse(requestData.recommendAsync || '[]'); | 1105 | + let recommendKeywords = requestData.recommendKeywords; |
1119 | let shopRecommend = requestData.shopRecommend; | 1106 | let shopRecommend = requestData.shopRecommend; |
1120 | let alike = requestData.alike; | 1107 | let alike = requestData.alike; |
1121 | let newProduct = requestData.newProduct; | 1108 | let newProduct = requestData.newProduct; |
@@ -1133,7 +1120,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) { | @@ -1133,7 +1120,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) { | ||
1133 | ); | 1120 | ); |
1134 | 1121 | ||
1135 | // 推荐关键词页面 | 1122 | // 推荐关键词页面 |
1136 | - result.recommendKeywords = getKeywordsInfo(recommendKeywords); | 1123 | + result.recommendKeywords = recommendKeywords; |
1137 | 1124 | ||
1138 | // 处理店铺推荐 | 1125 | // 处理店铺推荐 |
1139 | result.shopRecommend = productProcess.processProductList( | 1126 | result.shopRecommend = productProcess.processProductList( |
-
Please register or login to post a comment