Authored by yyq

sort cache

@@ -18,6 +18,7 @@ const crypto = global.yoho.crypto; @@ -18,6 +18,7 @@ const crypto = global.yoho.crypto;
18 const _ = require('lodash'); 18 const _ = require('lodash');
19 const md5 = require('md5'); 19 const md5 = require('md5');
20 const redis = global.yoho.redis; 20 const redis = global.yoho.redis;
  21 +const cache = global.yoho.cache;
21 22
22 // const limitNum = 60; // 商品每页显示数目 23 // const limitNum = 60; // 商品每页显示数目
23 const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime']; 24 const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
@@ -33,6 +34,20 @@ const positionId = 10; @@ -33,6 +34,20 @@ const positionId = 10;
33 // 获取分类左侧广告id 34 // 获取分类左侧广告id
34 const sortAdsId = 79; 35 const sortAdsId = 79;
35 36
  37 +const sortCache = {
  38 + key: 'global:yoho:category:name:',
  39 + get(categoryId) {
  40 + if (!categoryId) {
  41 + return Promise.resolve(false);
  42 + }
  43 +
  44 + return cache.get(this.key + categoryId);
  45 + },
  46 + set(categoryId, sortName) {
  47 + return cache.set(this.key + categoryId, sortName);
  48 + }
  49 +};
  50 +
36 /** 51 /**
37 * 获取商品分类列表数据 52 * 获取商品分类列表数据
38 */ 53 */
@@ -58,7 +73,8 @@ function getListData(params, channel) { @@ -58,7 +73,8 @@ function getListData(params, channel) {
58 let apiMethod = [ 73 let apiMethod = [
59 headerModel.requestHeaderData(channel, true), 74 headerModel.requestHeaderData(channel, true),
60 this.searchApi.getSortList({}, channel), 75 this.searchApi.getSortList({}, channel),
61 - this.searchApi.getProductList(searchParams, 'categoryList') 76 + this.searchApi.getProductList(searchParams, 'categoryList'),
  77 + sortCache.get(searchParams.category_id)
62 ]; 78 ];
63 79
64 // 搜索分类介绍和广告 80 // 搜索分类介绍和广告
@@ -125,13 +141,13 @@ function getListData(params, channel) { @@ -125,13 +141,13 @@ function getListData(params, channel) {
125 } 141 }
126 142
127 // 分类介绍 143 // 分类介绍
128 - if (result[3] && result[3].code === 200) {  
129 - finalResult.list.sortIntro = searchHandler.handleSortIntro(result[3].data); 144 + if (result[4] && result[4].code === 200) {
  145 + finalResult.list.sortIntro = searchHandler.handleSortIntro(result[4].data);
130 } 146 }
131 147
132 // 分类广告 148 // 分类广告
133 - if (result[4] && result[4].code === 200) {  
134 - Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data)); 149 + if (result[5] && result[5].code === 200) {
  150 + Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[5].data));
135 } 151 }
136 152
137 let sortName; 153 let sortName;
@@ -150,7 +166,20 @@ function getListData(params, channel) { @@ -150,7 +166,20 @@ function getListData(params, channel) {
150 } 166 }
151 }); 167 });
152 168
153 - const seo = seoHandler.getListSeo(sortList, checkedList); 169 + let extendParam = {};
  170 +
  171 + if (searchParams.category_id) {
  172 + let cacheSortName = result[3];
  173 +
  174 + if (!sortName && cacheSortName) {
  175 + sortName = cacheSortName;
  176 + extendParam.sort = cacheSortName;
  177 + } else if (sortName && sortName !== cacheSortName) {
  178 + sortCache.set(searchParams.category_id, sortName);
  179 + }
  180 + }
  181 +
  182 + const seo = seoHandler.getListSeo(sortList, checkedList, extendParam);
154 183
155 if (sortName) { 184 if (sortName) {
156 return redis.all([ 185 return redis.all([
@@ -85,8 +85,8 @@ const listDefaultTdk = { @@ -85,8 +85,8 @@ const listDefaultTdk = {
85 * @param checked 85 * @param checked
86 * @returns {{title: string, keywords: string, description: string}} 86 * @returns {{title: string, keywords: string, description: string}}
87 */ 87 */
88 -const getListSeo = (sorts, checked) => {  
89 - let {brand, channel, color, style, sort} = getSeoCheckedParamsName(sorts, checked); 88 +const getListSeo = (sorts, checked, extend = {}) => {
  89 + let {brand, channel, color, style, sort} = Object.assign(getSeoCheckedParamsName(sorts, checked), extend);
90 90
91 if (brand && _.indexOf(brand, '、') > -1) { 91 if (brand && _.indexOf(brand, '、') > -1) {
92 brand = ''; 92 brand = '';