Authored by yyq

Merge branch 'feature/qps' of git.yoho.cn:fe/yohobuy-node into feature/qps

... ... @@ -11,7 +11,8 @@ const _ = require('lodash');
const api = global.yoho.API;
const serviceApi = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
const keyPrefix = 'COMMON_HEADER_';
const cache = global.yoho.cache;
/**
* 获取菜单
* @param undefined
... ... @@ -214,31 +215,36 @@ const getHeaderNavAsync = () => {
* @param {String} 频道类型
* @return {promise}
*/
exports.requestHeaderData = (type) => {
async function requestHeaderData(type) {
let resData = {};
type = type || 'boys';
let headerKey = `${keyPrefix}${type}`;
let header = await cache.get(headerKey);
if (!header) {
let channelNum = (function() {
switch (type) {
case 'boys':
return 1;
case 'girls':
return 2;
case 'kids':
return 3;
case 'lifestyle':
return 4;
default:
return 1;
}
}());
let channelNum = (function() {
switch (type) {
case 'boys':
return 1;
case 'girls':
return 2;
case 'kids':
return 3;
case 'lifestyle':
return 4;
default:
return 1;
}
}());
let res = await Promise.all([
getHeaderNavAsync(),
getHotSearchAsync(channelNum)
return Promise.all([
getHeaderNavAsync(),
getHotSearchAsync(channelNum)
]);
]).then(res => {
resData.headerData = {};
if (res[0] && res[0].data) {
... ... @@ -258,6 +264,16 @@ exports.requestHeaderData = (type) => {
});
}
return resData;
});
if (res[0] && res[0].data && res[1] && res[1].data) {
cache.set(headerKey, resData, 300);
}
} else {
resData = JSON.parse(header);
}
return resData;
};
module.exports = {
requestHeaderData
}
... ...