Commit 2e9fdd00 by shenjunjie

渠道榜单缓存调优

parent c1b551c0
......@@ -162,7 +162,7 @@ public class ChannelRecord {
JSONObject json = new JSONObject(esMap);
this.rangeStartTime = json.getLongValue(RANGE_START_TIME);
this.rangeEndTime = json.getLongValue(RANGE_END_TIME);
this.platform = json.getString("platform");
this.platform = GlobalPojo.getPlatformNameById(json.getString("platform_id"));
this.realSource = json.getString("real_source");
this.source = json.getString("source");
this.projectId = json.getString("project_id");
......
......@@ -434,12 +434,28 @@ public class ChannelServiceImpl implements ChannelService {
List<ChannelListVO> resList = new ArrayList<>();
try {
String projectId = UserThreadLocal.getProjectId();
String redisKey = RedisUtil.getChannelRecordList(projectId, startTime, endTime, emotion);
// 部分条件不缓存
if (null != keyword) {
return getEmotionList(projectId, contendId, platform, keyword, sorter, startTime, endTime, size, emotion, cache);
}
String redisKey = RedisUtil.getChannelRecordList(projectId, startTime, endTime, platform, emotion);
String resultStr;
// 返回缓存
if (cache && StringUtils.isNotEmpty(resultStr = redisUtil.get(redisKey))) {
return JSON.parseArray(resultStr, ChannelListVO.class);
}
resList = getEmotionList(projectId, contendId, platform, keyword, sorter, startTime, endTime, size, emotion, cache);
// 配合天级缓存开启
redisUtil.setExpire(redisKey, JSON.toJSONString(resList));
} catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL, "es查询异常");
}
return resList;
}
private List<ChannelListVO> getEmotionList(String projectId, String contendId, String platform, String keyword, String sorter,
Long startTime, Long endTime, int size, int emotion, boolean cache) throws IOException {
List<ChannelListVO> resList = new ArrayList<>();
Map<String, Pair<Long, ChannelRecord>> keyMap = new HashMap<>();
EsClientDao.SearchHelper searchHelper = createSearchHelperByChannelCriteria(projectId, null,
Collections.singleton(contendId), platform, keyword, startTime, endTime);
......@@ -513,11 +529,6 @@ public class ChannelServiceImpl implements ChannelService {
resList.add(ChannelListVO.createFromChannel(record, record.getRecord().getArticles().size()));
}
});
// 配合天级缓存开启
redisUtil.setExpire(redisKey, JSON.toJSONString(resList));
} catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL, "es查询异常");
}
return resList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment