Authored by htoooth

Merge branch 'hotfix/add-cache' into feature/detail-op

# Conflicts:
#	apps/product/models/detail-product-api.js
#	apps/product/models/detail-service.js
... ... @@ -8,11 +8,12 @@ const config = global.yoho.config;
const redis = global.yoho.redis;
const cache = global.yoho.cache;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const _ = require('lodash');
const SearchServiceModel = require('./search-api');
const GuangServiceModel = require('../../guang/models/guang-service');
const productProcess = require('../../../utils/product-process');
const _ = require('lodash');
const uuid = require('uuid');
function _cacheGet(key) {
... ... @@ -34,7 +35,7 @@ function _cacheSave(key, value) {
}
function _cached(fn, ctx) {
const pre = (fn.name || 'random:' + uuid.v4()) + ':';
const pre = 'recommend-cache:' + (fn.name || 'random:' + uuid.v4()) + ':';
return function() {
const args = Array.prototype.slice.call(arguments);
... ... @@ -252,7 +253,22 @@ module.exports = class extends global.yoho.BaseModel {
getRecommendKeywords(smallSort) {
return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => {
return res[0];
}).then(result => {
return this._getKeywordsInfo(JSON.parse(result || '[]'));
})
}
// 返回6条推荐关键词页面
_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;
}
_getNewProduct(sort) {
... ...
... ... @@ -925,19 +925,6 @@ function _getIntroInfo(productSkn, maxSortId, additionalData) {
return result;
}
// 返回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;
}
/**
* 获取seo信息
*
... ... @@ -1115,7 +1102,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) {
let coupon = requestData.coupon;
let limitedInfo = requestData.limited;
let bundle = requestData.bundle;
let recommendKeywords = JSON.parse(requestData.recommendAsync || '[]');
let recommendKeywords = requestData.recommendKeywords;
let shopRecommend = requestData.shopRecommend;
let alike = requestData.alike;
let newProduct = requestData.newProduct;
... ... @@ -1133,7 +1120,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) {
);
// 推荐关键词页面
result.recommendKeywords = getKeywordsInfo(recommendKeywords);
result.recommendKeywords = recommendKeywords;
// 处理店铺推荐
result.shopRecommend = productProcess.processProductList(
... ...