|
@@ -249,10 +249,10 @@ public class RecallService implements ApplicationContextAware {
|
|
|
long start = System.currentTimeMillis();
|
|
|
contentList.forEach(content -> content.setTitleMd5(Md5Util.encoderByMd5(content.getTitle())));
|
|
|
List<String> sourceIdList = contentList.stream().map(Content::getSourceId).distinct().collect(Collectors.toList());
|
|
|
- Map<String, Content> sourceContentMap = contentList.stream().collect(
|
|
|
+ Map<String, Content> sourceIdToContentMap = contentList.stream().collect(
|
|
|
Collectors.toMap(Content::getSourceId, Function.identity(), (o1, o2) -> o2));
|
|
|
// 根据sourceId查询数据库获取数据
|
|
|
- List<ArticleTitleHisCache> articleTitleHisCacheList = new ArrayList<>();
|
|
|
+ List<ArticleTitleHisCache> articleTitleHisCacheList = new ArrayList<>(sourceIdList.size());
|
|
|
for (List<String> partition : Lists.partition(sourceIdList, 1000)) {
|
|
|
articleTitleHisCacheList.addAll(articleTitleHisCacheRepository.getBySourceIdInAndType(partition, type));
|
|
|
}
|
|
@@ -265,7 +265,7 @@ public class RecallService implements ApplicationContextAware {
|
|
|
Map<String, Double> accountCorrelationMap = accountCorrelationList.stream().collect(
|
|
|
Collectors.toMap(AccountCorrelation::getRelGhId, AccountCorrelation::getCorrelation));
|
|
|
List<TitleHisCacheParam> paramList = sourceIdList.stream().map(sourceId -> {
|
|
|
- Content content = sourceContentMap.get(sourceId);
|
|
|
+ Content content = sourceIdToContentMap.get(sourceId);
|
|
|
TitleHisCacheParam cacheParam = new TitleHisCacheParam();
|
|
|
cacheParam.setSourceId(sourceId);
|
|
|
cacheParam.setTitleMd5(content.getTitleMd5());
|
|
@@ -275,9 +275,9 @@ public class RecallService implements ApplicationContextAware {
|
|
|
cacheParam.setCategory(content.getCategory());
|
|
|
return cacheParam;
|
|
|
}).collect(Collectors.toList());
|
|
|
- Map<String, Content> hisArticleCacheMap = getArticleTitleHisCacheMap(paramList, type);
|
|
|
- List<Content> saveList = new ArrayList<>();
|
|
|
- Set<String> sourceSet = new HashSet<>();
|
|
|
+ Map<String, Content> articlesWithHistory = getArticleWithHistory(paramList, type);
|
|
|
+ List<Content> newCacheSaveList = new ArrayList<>();
|
|
|
+ Set<String> newCacheSourceIdSet = new HashSet<>();
|
|
|
for (Content content : contentList) {
|
|
|
if (articleTitleHisCacheMap.containsKey(content.getSourceId())) {
|
|
|
ArticleTitleHisCache cache = articleTitleHisCacheMap.get(content.getSourceId());
|
|
@@ -294,25 +294,25 @@ public class RecallService implements ApplicationContextAware {
|
|
|
setT0Data(content);
|
|
|
continue;
|
|
|
}
|
|
|
- if (hisArticleCacheMap.containsKey(content.getSourceId())) {
|
|
|
- Content cache = hisArticleCacheMap.get(content.getSourceId());
|
|
|
- content.setHisPublishArticleList(cache.getHisPublishArticleList());
|
|
|
- if (CollectionUtils.isNotEmpty(cache.getCategory())) {
|
|
|
- content.setCategory(cache.getCategory());
|
|
|
+ if (articlesWithHistory.containsKey(content.getSourceId())) {
|
|
|
+ Content articleWithHistory = articlesWithHistory.get(content.getSourceId());
|
|
|
+ content.setHisPublishArticleList(articleWithHistory.getHisPublishArticleList());
|
|
|
+ if (CollectionUtils.isNotEmpty(articleWithHistory.getCategory())) {
|
|
|
+ content.setCategory(articleWithHistory.getCategory());
|
|
|
}
|
|
|
- content.setRootPublishTimestamp(cache.getRootPublishTimestamp());
|
|
|
+ content.setRootPublishTimestamp(articleWithHistory.getRootPublishTimestamp());
|
|
|
for (ContentHisPublishArticle article : content.getHisPublishArticleList()) {
|
|
|
article.setCorrelation(Optional.ofNullable(accountCorrelationMap.get(article.getGhId())).orElse(0.0));
|
|
|
}
|
|
|
setT0Data(content);
|
|
|
}
|
|
|
- if (!sourceSet.contains(content.getSourceId())) {
|
|
|
- saveList.add(content);
|
|
|
- sourceSet.add(content.getSourceId());
|
|
|
+ if (!newCacheSourceIdSet.contains(content.getSourceId())) {
|
|
|
+ newCacheSaveList.add(content);
|
|
|
+ newCacheSourceIdSet.add(content.getSourceId());
|
|
|
}
|
|
|
}
|
|
|
// 写入缓存
|
|
|
- saveArticleTitleHisCache(saveList, type);
|
|
|
+ saveArticleTitleHisCache(newCacheSaveList, type);
|
|
|
log.info("setTitleAvgViewCount cost:{}", System.currentTimeMillis() - start);
|
|
|
}
|
|
|
|
|
@@ -347,7 +347,7 @@ public class RecallService implements ApplicationContextAware {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Map<String, Content> getArticleTitleHisCacheMap(List<TitleHisCacheParam> paramList, String type) {
|
|
|
+ public Map<String, Content> getArticleWithHistory(List<TitleHisCacheParam> paramList, String type) {
|
|
|
Map<String, Content> result = new HashMap<>();
|
|
|
List<String> titleMd5List = paramList.stream().map(TitleHisCacheParam::getTitleMd5).collect(Collectors.toList());
|
|
|
// 获取历史已发布文章
|