Explorar o código

TodayPublishStrategy fix

wangyunpeng hai 2 días
pai
achega
1b5800b66c

+ 32 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/strategy/TodayPublishStrategy.java

@@ -1,5 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.recommend.filter.strategy;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import com.tzld.longarticle.recommend.server.common.CommonThreadPoolExecutor;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishContent;
@@ -8,11 +10,13 @@ import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterResu
 import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterStrategy;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.*;
 import java.util.stream.Collectors;
 
 @Component
@@ -22,19 +26,41 @@ public class TodayPublishStrategy implements FilterStrategy {
     @Autowired
     private AigcBaseMapper aigcBaseMapper;
 
+    private final static ExecutorService pool = new CommonThreadPoolExecutor(
+            8,
+            8,
+            0L, TimeUnit.SECONDS,
+            new LinkedBlockingQueue<>(100),
+            new ThreadFactoryBuilder().setNameFormat("TodayPublishStrategy-%d").build(),
+            new ThreadPoolExecutor.AbortPolicy());
+
     @Override
     public FilterResult filter(FilterParam param) {
+        Long start = System.currentTimeMillis();
         FilterResult filterResult = new FilterResult();
-        List<String> result = new ArrayList<>(param.getContents().size());
+        List<String> result = Collections.synchronizedList(param.getContents().stream().map(Content::getId).collect(Collectors.toList()));
         Long todayStart = DateUtils.getTodayStart();
         List<PublishContent> todayPublishContentList = aigcBaseMapper.getTodayPublishContentList(param.getAccountId(), todayStart);
-        List<String> todayPublishContentIdList = todayPublishContentList.stream().map(PublishContent::getId).collect(Collectors.toList());
-        for (Content content : param.getContents()) {
-            if (!todayPublishContentIdList.contains(content.getId())) {
-                result.add(content.getId());
+        if (CollectionUtils.isNotEmpty(todayPublishContentList)) {
+            List<String> todayPublishContentIdList = todayPublishContentList.stream().map(PublishContent::getId).collect(Collectors.toList());
+            CountDownLatch cdl = new CountDownLatch(todayPublishContentIdList.size());
+            for (String todayPublishContentId : todayPublishContentIdList) {
+                pool.submit(() -> {
+                    try {
+                        result.remove(todayPublishContentId);
+                    } finally {
+                        cdl.countDown();
+                    }
+                });
+            }
+            try {
+                cdl.await();
+            } catch (InterruptedException e) {
+                log.error("TodayPublishStrategy filter error", e);
             }
         }
         filterResult.setContentIds(result);
+        log.info("TodayPublishStrategy filter cost time:{}", System.currentTimeMillis() - start);
         return filterResult;
     }
 

+ 2 - 2
long-article-recommend-service/src/main/resources/application-prod.yml

@@ -109,10 +109,10 @@ aliyun:
     endpoint: cn-hangzhou-intranet.log.aliyuncs.com
     accessKeyId: LTAIP6x1l3DXfSxm
     accessKeySecret: KbTaM9ars4OX3PMS6Xm7rtxGr1FLon
-    project: longarticle-recommend-server-test
+    project: longarticle-recommend-server
   timer:
     log:
-      project: longarticle-recommend-server-test
+      project: longarticle-recommend-server
       logStore: timer
 
 pushMessage:

+ 3 - 8
long-article-recommend-service/src/main/resources/application-test.yml

@@ -139,19 +139,14 @@ apollo:
 
 aliyun:
   log:
-    endpoint: cn-hangzhou-intranet.log.aliyuncs.com
+    endpoint: cn-hangzhou.log.aliyuncs.com
     accessKeyId: LTAIP6x1l3DXfSxm
     accessKeySecret: KbTaM9ars4OX3PMS6Xm7rtxGr1FLon
-    project: recommend-server-test
+    project: longarticle-recommend-server-test
   timer:
     log:
-      project: recommend-server-test
+      project: longarticle-recommend-server-test
       logStore: timer
-  blacklist:
-    filter:
-      log:
-        project: wqsd-video-test
-        store: video_blacklist_security_filter_log
 
 small_page_url: https://testapi.piaoquantv.com