Browse Source

每天晚上随机全量同步

wangyunpeng 4 weeks ago
parent
commit
97629346d0

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/longArticle/LongArticleBaseMapper.java

@@ -112,4 +112,6 @@ public interface LongArticleBaseMapper {
     void updatePublishContentGzhWaitingStatusByIds(List<String> contentIds, Integer status);
 
     List<PublishPlanAccountDTO> getGroupPublishPlanAccounts();
+
+    Long getMinGzhWaitingPublishContent(String planId, String accountId);
 }

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/aigc/AIGCWaitingPublishContentService.java

@@ -96,7 +96,7 @@ public class AIGCWaitingPublishContentService {
             List<Content> contentList = getAllContent(planId, accountId, null);
             if (CollectionUtil.isNotEmpty(contentList)) {
                 Long now = System.currentTimeMillis();
-                CompletableFuture.runAsync(() -> xxlJobService.savePublishContentCache(contentList, planId, accountId, now));
+                CompletableFuture.runAsync(() -> xxlJobService.savePublishContentCache(contentList, planId, accountId, true, now));
             }
             return contentList;
         }

+ 15 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -1000,6 +1000,7 @@ public class XxlJobService {
         Map<String, Map<String, Integer>> existAccountMap = existAccountList.stream().collect(
                 Collectors.groupingBy(PublishPlanAccountDTO::getPlanId,
                         Collectors.toMap(PublishPlanAccountDTO::getAccountId, PublishPlanAccountDTO::getCnt)));
+        int hour = DateUtils.getHourByTimestamp(now / 1000);
 
         ExecutorService thread = new CommonThreadPoolExecutor(
                 syncPublishContentThreadPoolSize, syncPublishContentThreadPoolSize, 0L, TimeUnit.SECONDS,
@@ -1014,9 +1015,16 @@ public class XxlJobService {
                     if (existAccountMap.containsKey(account.getPlanId())) {
                         cnt = existAccountMap.get(account.getPlanId()).getOrDefault(account.getAccountId(), 0);
                     }
-                    List<Content> contentList = aigcWaitingPublishContentService.getAllContent(account.getPlanId(),account.getAccountId()
-                            , cnt > 0 ? newAuditIds : null);
-                    savePublishContentCache(contentList, account.getPlanId(), account.getAccountId(), now);
+                    List<Content> contentList;
+                    // 每天晚上随机全量同步
+                    boolean findAll = hour > 20 && Math.random() > 0.5;
+                    if (findAll) {
+                        contentList = aigcWaitingPublishContentService.getAllContent(account.getPlanId(), account.getAccountId(), null);
+                    } else {
+                        contentList = aigcWaitingPublishContentService.getAllContent(account.getPlanId(), account.getAccountId()
+                                , cnt > 0 ? newAuditIds : null);
+                    }
+                    savePublishContentCache(contentList, account.getPlanId(), account.getAccountId(), findAll, now);
                 } finally {
                     cdl.countDown();
                 }
@@ -1049,13 +1057,15 @@ public class XxlJobService {
         item.setUpdateTimestamp(updateTimestamp);
     }
 
-    public void savePublishContentCache(List<Content> contentList, String planId, String accountId, Long now) {
+    public void savePublishContentCache(List<Content> contentList, String planId, String accountId, Boolean findAll, Long now) {
         if (CollectionUtil.isEmpty(contentList)) {
             return;
         }
         List<String> contentIds = contentList.stream().map(Content::getId).collect(Collectors.toList());
         // 不存在状态置0
-//        longArticleBaseMapper.updatePublishContentGzhWaitingStatus(planId, accountId, contentIds, 0, now);
+        if (findAll) {
+            longArticleBaseMapper.updatePublishContentGzhWaitingStatus(planId, accountId, contentIds, 0, now);
+        }
         List<PublishContentGzhWaiting> existList = publishContentGzhWaitingRepository.getByIdIn(contentIds);
         List<String> existContentIds = existList.stream().map(PublishContentGzhWaiting::getId).collect(Collectors.toList());
         Map<String, PublishContentGzhWaiting> existMap = existList.stream().collect(

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/FilterParam.java

@@ -12,6 +12,7 @@ import java.util.List;
 public class FilterParam {
     private String accountName;
     private List<Content> contents;
+    private String planId;
     private String accountId;
     private String strategy;
     private String ghId;

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/recall/FilterParamFactory.java

@@ -13,6 +13,7 @@ public class FilterParamFactory {
         FilterParam filterParam = new FilterParam();
         filterParam.setAccountName(param.getAccountName());
         filterParam.setContents(contents);
+        filterParam.setPlanId(param.getPlanId());
         filterParam.setAccountId(param.getAccountId());
         filterParam.setStrategy(param.getStrategy());
         filterParam.setGhId(param.getGhId());

+ 8 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/LongArticleBaseMapper.xml

@@ -465,4 +465,12 @@
         GROUP BY plan_id, publish_account_id
     </select>
 
+    <select id="getMinGzhWaitingPublishContent" resultType="java.lang.Long">
+        select min(update_timestamp)
+        from publish_content_gzh_waiting
+        where plan_id = #{planId}
+        and publish_account_id = #{accountId}
+        and status = 1
+    </select>
+
 </mapper>