Commit 5a46aaa5 by shenjunjie

Merge branch 'feature' into 'dev'

渠道榜单缓存调优

See merge request !165
parents a9f6e67f 2e9fdd00
...@@ -162,7 +162,7 @@ public class ChannelRecord { ...@@ -162,7 +162,7 @@ public class ChannelRecord {
JSONObject json = new JSONObject(esMap); JSONObject json = new JSONObject(esMap);
this.rangeStartTime = json.getLongValue(RANGE_START_TIME); this.rangeStartTime = json.getLongValue(RANGE_START_TIME);
this.rangeEndTime = json.getLongValue(RANGE_END_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.realSource = json.getString("real_source");
this.source = json.getString("source"); this.source = json.getString("source");
this.projectId = json.getString("project_id"); this.projectId = json.getString("project_id");
......
...@@ -434,12 +434,28 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -434,12 +434,28 @@ public class ChannelServiceImpl implements ChannelService {
List<ChannelListVO> resList = new ArrayList<>(); List<ChannelListVO> resList = new ArrayList<>();
try { try {
String projectId = UserThreadLocal.getProjectId(); 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; String resultStr;
// 返回缓存 // 返回缓存
if (cache && StringUtils.isNotEmpty(resultStr = redisUtil.get(redisKey))) { if (cache && StringUtils.isNotEmpty(resultStr = redisUtil.get(redisKey))) {
return JSON.parseArray(resultStr, ChannelListVO.class); 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<>(); Map<String, Pair<Long, ChannelRecord>> keyMap = new HashMap<>();
EsClientDao.SearchHelper searchHelper = createSearchHelperByChannelCriteria(projectId, null, EsClientDao.SearchHelper searchHelper = createSearchHelperByChannelCriteria(projectId, null,
Collections.singleton(contendId), platform, keyword, startTime, endTime); Collections.singleton(contendId), platform, keyword, startTime, endTime);
...@@ -513,11 +529,6 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -513,11 +529,6 @@ public class ChannelServiceImpl implements ChannelService {
resList.add(ChannelListVO.createFromChannel(record, record.getRecord().getArticles().size())); 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; 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