소스 검색

Merge branch 'feature/20241130-improve-perf2' of Server/long-article-recommend into master

fengzhoutian 7 달 전
부모
커밋
b395f9f4c8

+ 4 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/strategy/DeDuplicationStrategy.java

@@ -48,11 +48,11 @@ public class DeDuplicationStrategy implements FilterStrategy {
             List<Content> contents = contentMap.get(contentPool);
             Future<List<Content>> future = pool.submit(() -> {
                 try {
-                    List<Content> res = new ArrayList<>();
-                    Set<String> titles = new HashSet<>();
                     if (CollectionUtils.isEmpty(contents)) {
                         return new ArrayList<>();
                     }
+                    List<Content> res = new ArrayList<>(contents.size());
+                    Set<String> titles = new HashSet<>(contents.size());
                     for (Content c : contents) {
                         if (titles.contains(c.getTitle())) {
                             c.setFilterReason("重复文章");
@@ -87,8 +87,8 @@ public class DeDuplicationStrategy implements FilterStrategy {
     }
 
     private List<String> groupDeduplication(List<Content> contentList, List<Content> filterContents) {
-        List<String> result = new ArrayList<>();
-        Set<String> titles = new HashSet<>();
+        List<String> result = new ArrayList<>(contentList.size());
+        Set<String> titles = new HashSet<>(contentList.size());
         Map<String, List<Content>> contentMap = contentList.stream().collect(Collectors.groupingBy(Content::getContentPoolType));
 
         List<String> contentPoolList = ContentPoolEnum.getOrderContentPool();