Authored by unknown

优化接口缓存

... ... @@ -17,7 +17,7 @@ public interface IAggRecommendService {
public SearchApiResult aggRecommendBrand(Map<String, String> paramMap);
/**
* 获取品牌的聚合结果[使用本地缓存][按参数决定是否返回全球购品牌]
* 获取品牌的聚合结果[使用本地缓存]
*
* @param paramMap
* @return
... ...
package com.yoho.search.service.servicenew.scene;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
... ... @@ -47,6 +48,11 @@ public class FuzzySceneService extends AbstractSceneService {
return SearchPageIdDefine.PAGE_ID_SEARCH;
}
private void addParamsToParamMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());
paramMap.put("aggWithParamBrand", "Y");
}
/**
* @1、返回商品列表
* @2、数量太多则返回建议词
... ... @@ -54,6 +60,8 @@ public class FuzzySceneService extends AbstractSceneService {
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、添加默认参数
this.addParamsToParamMap(paramMap);
// 1、获取商品列表
SearchApiResult searchApiResult = splitProductListService.productList(paramMap);
// 2)、加入建议词
... ... @@ -110,15 +118,30 @@ public class FuzzySceneService extends AbstractSceneService {
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
// 1、获取通用筛选项
JSONObject commonFilters = splitSelectionsService.getCommonFilters(paramMap);
// 2、获取推荐的品牌
Object recommendBrand = splitSelectionsService.getRecommendBrands(paramMap);
if (recommendBrand != null) {
commonFilters.put("recommendBrand", recommendBrand);
try {
// 0、添加默认参数
this.addParamsToParamMap(paramMap);
// 1、获取通用筛选项
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
return splitSelectionsService.getCommonFilters(paramMap);
}, executorService);
// 2、获取推荐的品牌
CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
return splitSelectionsService.getRecommendBrands(paramMap);
}, executorService);
// 3、组合
JSONObject commonFilters = commonFiltersFuture.get();
Object recommendBrand = recommendBrandFuture.get();
if (recommendBrand != null) {
commonFilters.put("recommendBrand", recommendBrand);
}
// 4、返回最终结果
Map<String, Object> result = new JSONObject();
result.put("filter", commonFilters);
return new SearchApiResult().setData(result);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setData(null).setMessage("FuzzyAggregations Exception").setCode(500);
}
Map<String, Object> result = new JSONObject();
result.put("filter", commonFilters);
return new SearchApiResult().setData(result);
}
}
... ...
... ... @@ -5,8 +5,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -23,6 +21,7 @@ import com.yoho.search.service.servicenew.IProductIndexService;
import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
@Service
... ... @@ -46,11 +45,16 @@ public class SortSceneService extends AbstractSceneService {
return SearchPageIdDefine.PAGE_ID_SORT;
}
private ExecutorService executorService = Executors.newFixedThreadPool(100);
private void addParamsToParamMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());
paramMap.put("aggWithParamBrand", "Y");
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、添加默认参数
this.addParamsToParamMap(paramMap);
// 1、获取商品列表
CompletableFuture<SearchApiResult> productListFuture = CompletableFuture.supplyAsync(() -> {
return splitProductListService.productList(paramMap);
... ... @@ -74,6 +78,8 @@ public class SortSceneService extends AbstractSceneService {
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 0、添加默认参数
this.addParamsToParamMap(paramMap);
// 1、获取通用筛选项
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
return splitSelectionsService.getCommonFilters(paramMap);
... ...
package com.yoho.search.service.servicenew.scene.common;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.yoho.search.service.vo.SearchApiResult;
public abstract class AbstractSceneService {
protected static ExecutorService executorService = Executors.newFixedThreadPool(500);
public abstract String pageId();
public abstract SearchApiResult productList(Map<String, String> paramMap);
public abstract SearchApiResult aggregations(Map<String, String> paramMap);
}
... ...