浏览代码

cold start

丁云鹏 11 月之前
父节点
当前提交
3ea60ec1ec

+ 3 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/ArticlePreDistributeAccountRepository.java

@@ -4,10 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.stereotype.Repository;
 
+import java.util.Optional;
+
 @Repository
 public interface ArticlePreDistributeAccountRepository extends JpaRepository<ArticlePreDistributeAccount,
         ArticlePreDistributeAccount.PK> {
 
     @Query("SELECT t FROM ArticlePreDistributeAccount t WHERE t.ghId = :ghId ORDER BY t.date DESC")
-    ArticlePreDistributeAccount findByGhIdOrderByDate(String ghId);
+    Optional<ArticlePreDistributeAccount> findTopByGhId(String ghId);
 }

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

@@ -35,11 +35,10 @@ public class AccountPreDistributeStrategy implements FilterStrategy {
         List<Content> filterContents = new ArrayList<>();
         String[] pools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         if (pools.length >= 3) {
-            ArticlePreDistributeAccount articlePreDistributeAccount =
-                    articlePreDistributeAccountRepository.findByGhIdOrderByDate(param.getAccountId());
+            Optional<ArticlePreDistributeAccount> optional = articlePreDistributeAccountRepository.findTopByGhId(param.getGhId());
             Set<String> articles = new HashSet<>();
-            if (articlePreDistributeAccount != null && StringUtils.isNotEmpty(articlePreDistributeAccount.getArticleList())) {
-                List<String[]> list = JSONUtils.fromJson(articlePreDistributeAccount.getArticleList(), new TypeToken<List<String[]>>() {
+            if (optional.isPresent() && StringUtils.isNotEmpty(optional.get().getArticleList())) {
+                List<String[]> list = JSONUtils.fromJson(optional.get().getArticleList(), new TypeToken<List<String[]>>() {
                 }, Collections.emptyList());
                 for (String[] s : list) {
                     articles.add(s[0]);
@@ -48,7 +47,7 @@ public class AccountPreDistributeStrategy implements FilterStrategy {
 
             for (Content content : contents) {
                 if (StringUtils.equals(pools[2], content.getContentPoolType())) {
-                    if (articles.contains(content.getId())) {
+                    if (articles.contains(content.getCrawlerChannelContentId())) {
                         result.add(content.getId());
                     }
                 } else {

+ 3 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV3Strategy.java

@@ -66,6 +66,8 @@ public class RankV3Strategy implements RankStrategy {
         });
         // 2 相似去重
         List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
+        log.info("Sort result {}", JSONUtils.toJson(contents));
+
         contents = deduplication(contents);
         log.info("Deduplication {}", JSONUtils.toJson(contents));
 
@@ -75,7 +77,7 @@ public class RankV3Strategy implements RankStrategy {
             List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
             data.add(c);
         }
-
+        log.info("ContentMap {}", JSONUtils.toJson(contentMap));
         // 4 选文章
         List<Content> result = new ArrayList<>();
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());