|
@@ -758,50 +758,53 @@ public class XxlJobService {
|
|
|
int pageSize = 500;
|
|
|
long page = (count / pageSize) + 1;
|
|
|
for (int i = 0; i < page; i++) {
|
|
|
- Page<ArticleTitleHisCache> articleTitleHisCachePage = articleTitleHisCacheRepository.findAll(
|
|
|
- PageRequest.of(i, pageSize));
|
|
|
- List<ArticleTitleHisCache> cacheList = articleTitleHisCachePage.getContent();
|
|
|
- if (CollectionUtils.isEmpty(cacheList)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- Map<String, Map<String, ArticleTitleHisCache>> cacheMap = cacheList.stream().collect(
|
|
|
- Collectors.groupingBy(ArticleTitleHisCache::getType,
|
|
|
- Collectors.toMap(ArticleTitleHisCache::getSourceId, Function.identity())));
|
|
|
- for (Map.Entry<String, Map<String, ArticleTitleHisCache>> typeEntry : cacheMap.entrySet()) {
|
|
|
- String type = typeEntry.getKey();
|
|
|
- Map<String, ArticleTitleHisCache> sourceIdToCacheMap = typeEntry.getValue();
|
|
|
- Set<String> sourceIdList = sourceIdToCacheMap.keySet();
|
|
|
- List<TitleHisCacheParam> paramList = sourceIdList.stream().map(sourceId -> {
|
|
|
- ArticleTitleHisCache cache = cacheMap.get(type).get(sourceId);
|
|
|
- TitleHisCacheParam cacheParam = new TitleHisCacheParam();
|
|
|
- cacheParam.setSourceId(sourceId);
|
|
|
- cacheParam.setTitleMd5(cache.getTitleMd5());
|
|
|
- cacheParam.setTitle(cache.getTitle());
|
|
|
- cacheParam.setCrawlerTitle(cache.getCrawlerTitle());
|
|
|
- cacheParam.setCrawlerChannelContentId(cache.getChannelContentId());
|
|
|
- if (StringUtils.hasText(cache.getCategory())) {
|
|
|
- cacheParam.setCategory(JSONArray.parseArray(cache.getCategory(), String.class));
|
|
|
- }
|
|
|
- return cacheParam;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- Map<String, Content> articlesWithHistory = recallService.getArticleWithHistory(paramList, type);
|
|
|
- for (String sourceId : sourceIdList) {
|
|
|
- Content content = articlesWithHistory.get(sourceId);
|
|
|
- if (Objects.nonNull(content) && CollectionUtils.isNotEmpty(content.getHisPublishArticleList())) {
|
|
|
- ArticleTitleHisCache cache = sourceIdToCacheMap.get(sourceId);
|
|
|
- cache.setHisPublishArticleList(JSONObject.toJSONString(content.getHisPublishArticleList()));
|
|
|
- if (CollectionUtil.isNotEmpty(content.getCategory())) {
|
|
|
- cache.setCategory(JSONObject.toJSONString(content.getCategory()));
|
|
|
- }
|
|
|
- cache.setKimiSafeScore(content.getKimiSafeScore());
|
|
|
- cache.setUpdateTimestamp(System.currentTimeMillis());
|
|
|
- articleTitleHisCacheRepository.save(cache);
|
|
|
+ batchRefreshArticleHisCache(i, pageSize);
|
|
|
+ }
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void batchRefreshArticleHisCache(int i, int pageSize) {
|
|
|
+ Page<ArticleTitleHisCache> articleTitleHisCachePage = articleTitleHisCacheRepository.findAll(
|
|
|
+ PageRequest.of(i, pageSize));
|
|
|
+ List<ArticleTitleHisCache> cacheList = articleTitleHisCachePage.getContent();
|
|
|
+ if (CollectionUtils.isEmpty(cacheList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Map<String, ArticleTitleHisCache>> cacheMap = cacheList.stream().collect(
|
|
|
+ Collectors.groupingBy(ArticleTitleHisCache::getType,
|
|
|
+ Collectors.toMap(ArticleTitleHisCache::getSourceId, Function.identity())));
|
|
|
+ for (Map.Entry<String, Map<String, ArticleTitleHisCache>> typeEntry : cacheMap.entrySet()) {
|
|
|
+ String type = typeEntry.getKey();
|
|
|
+ Map<String, ArticleTitleHisCache> sourceIdToCacheMap = typeEntry.getValue();
|
|
|
+ Set<String> sourceIdList = sourceIdToCacheMap.keySet();
|
|
|
+ List<TitleHisCacheParam> paramList = sourceIdList.stream().map(sourceId -> {
|
|
|
+ ArticleTitleHisCache cache = cacheMap.get(type).get(sourceId);
|
|
|
+ TitleHisCacheParam cacheParam = new TitleHisCacheParam();
|
|
|
+ cacheParam.setSourceId(sourceId);
|
|
|
+ cacheParam.setTitleMd5(cache.getTitleMd5());
|
|
|
+ cacheParam.setTitle(cache.getTitle());
|
|
|
+ cacheParam.setCrawlerTitle(cache.getCrawlerTitle());
|
|
|
+ cacheParam.setCrawlerChannelContentId(cache.getChannelContentId());
|
|
|
+ if (StringUtils.hasText(cache.getCategory())) {
|
|
|
+ cacheParam.setCategory(JSONArray.parseArray(cache.getCategory(), String.class));
|
|
|
+ }
|
|
|
+ return cacheParam;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Map<String, Content> articlesWithHistory = recallService.getArticleWithHistory(paramList, type);
|
|
|
+ for (String sourceId : sourceIdList) {
|
|
|
+ Content content = articlesWithHistory.get(sourceId);
|
|
|
+ if (Objects.nonNull(content) && CollectionUtils.isNotEmpty(content.getHisPublishArticleList())) {
|
|
|
+ ArticleTitleHisCache cache = sourceIdToCacheMap.get(sourceId);
|
|
|
+ cache.setHisPublishArticleList(JSONObject.toJSONString(content.getHisPublishArticleList()));
|
|
|
+ if (CollectionUtil.isNotEmpty(content.getCategory())) {
|
|
|
+ cache.setCategory(JSONObject.toJSONString(content.getCategory()));
|
|
|
}
|
|
|
+ cache.setKimiSafeScore(content.getKimiSafeScore());
|
|
|
+ cache.setUpdateTimestamp(System.currentTimeMillis());
|
|
|
+ articleTitleHisCacheRepository.save(cache);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
|
}
|