Преглед изворни кода

Merge branch 'cooperation_video_candidate_pool_improved_lld_0509' of Server/growth-manager into master

liulidong пре 6 часа
родитељ
комит
29935a4d5a

+ 4 - 3
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/contentplatform/ext/ContentPlatformDemandVideoMapperExt.java

@@ -32,11 +32,12 @@ public interface ContentPlatformDemandVideoMapperExt {
     String getMaxDt(@Param("channelName") String channelName);
     String getMaxDt(@Param("channelName") String channelName);
 
 
     /**
     /**
-     * 按 ghName(channel_level3) 反查所属 channel_name。
-     * 业务约定一个公众号只归属一个 channel,故 LIMIT 1。
+     * 按 ghName(channel_level3) 反查所属 channel_name,取该 gh 最新分区的一行。
+     * 业务约定一个公众号只归属一个 channel,故 ORDER BY dt DESC LIMIT 1。
+     * (不再先单独查全表 MAX(dt),省掉无 channel 过滤的全表扫描。)
      * 未命中返回 null,由调用方决定回退。
      * 未命中返回 null,由调用方决定回退。
      */
      */
-    String selectChannelNameByGh(@Param("dt") String dt, @Param("ghName") String ghName);
+    String selectChannelNameByGh(@Param("ghName") String ghName);
 
 
     /**
     /**
      * 推荐场景候选池查询:按 demand_strategy 取指定 crowd_segment 的候选行,
      * 推荐场景候选池查询:按 demand_strategy 取指定 crowd_segment 的候选行,

+ 17 - 17
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformPlanServiceImpl.java

@@ -692,10 +692,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         }
         }
         String ghName = param.getGhName();
         String ghName = param.getGhName();
         if (StringUtils.hasText(ghName)) {
         if (StringUtils.hasText(ghName)) {
-            String dt = demandVideoMapperExt.getMaxDt(null);
-            if (StringUtils.hasText(dt)) {
-                return DemandChannelEnum.fromValue(demandVideoMapperExt.selectChannelNameByGh(dt, ghName));
-            }
+            return DemandChannelEnum.fromValue(demandVideoMapperExt.selectChannelNameByGh(ghName));
         }
         }
         return null;
         return null;
     }
     }
@@ -768,6 +765,9 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         if (VideoContentSource.HOT == source) {
         if (VideoContentSource.HOT == source) {
             return getHotSourcePaged(param, user);
             return getHotSourcePaged(param, user);
         }
         }
+        // 杠杆1: channel + dt 每请求只解析一次,传入各池,避免 fan-out 各池重复查 channel/dt
+        DemandChannelEnum channel = resolveChannelName(param);
+        String dt = demandVideoMapperExt.getMaxDt(channel == null ? null : channel.getValue());
         List<VideoContentItemVO> list;
         List<VideoContentItemVO> list;
         if (VideoContentSource.PRIOR == source) {
         if (VideoContentSource.PRIOR == source) {
             // 人群需求池并行拉取, 按 PRIOR_POOL_CONFIGS 配置
             // 人群需求池并行拉取, 按 PRIOR_POOL_CONFIGS 配置
@@ -777,8 +777,8 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
                 List<Future<List<VideoContentItemVO>>> futures = new ArrayList<>(poolCount);
                 List<Future<List<VideoContentItemVO>>> futures = new ArrayList<>(poolCount);
                 for (PriorPoolConfig cfg : PRIOR_POOL_CONFIGS) {
                 for (PriorPoolConfig cfg : PRIOR_POOL_CONFIGS) {
                     futures.add(executor.submit(cfg.scene
                     futures.add(executor.submit(cfg.scene
-                            ? () -> fetchPriorSceneCandidates(param, user, DEMAND_CANDIDATE_LIMIT, cfg.dimension, cfg.demandType, cfg.matchMethod)
-                            : () -> fetchPriorPool(param, user, DEMAND_CANDIDATE_LIMIT, cfg.dimension, cfg.demandType, cfg.matchMethod)));
+                            ? () -> fetchPriorSceneCandidates(param, user, DEMAND_CANDIDATE_LIMIT, channel, dt, cfg.dimension, cfg.demandType, cfg.matchMethod)
+                            : () -> fetchPriorPool(param, user, DEMAND_CANDIDATE_LIMIT, channel, dt, cfg.dimension, cfg.demandType, cfg.matchMethod)));
                 }
                 }
 
 
                 int timeoutSeconds = 30;
                 int timeoutSeconds = 30;
@@ -795,7 +795,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
                 executor.shutdown();
                 executor.shutdown();
             }
             }
         } else {
         } else {
-            list = fetchPosteriorCandidates(param, user, DEMAND_CANDIDATE_LIMIT);
+            list = fetchPosteriorCandidates(param, user, DEMAND_CANDIDATE_LIMIT, channel, dt);
         }
         }
         for (VideoContentItemVO v : list) {
         for (VideoContentItemVO v : list) {
             v.setSource(source.getValue());
             v.setSource(source.getValue());
@@ -927,18 +927,21 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
     private Page<VideoContentItemVO> getInterleavedPage(VideoContentListParam param, ContentPlatformAccount user) {
     private Page<VideoContentItemVO> getInterleavedPage(VideoContentListParam param, ContentPlatformAccount user) {
         int priorCount = PRIOR_POOL_CONFIGS.size();
         int priorCount = PRIOR_POOL_CONFIGS.size();
         int totalCount = priorCount + 2; // + posterior + hot
         int totalCount = priorCount + 2; // + posterior + hot
+        // 杠杆1: channel + dt 每请求只解析一次,传入各 demand 池(hot 池用自己的 dt,不受影响)
+        DemandChannelEnum channel = resolveChannelName(param);
+        String dt = demandVideoMapperExt.getMaxDt(channel == null ? null : channel.getValue());
         ExecutorService executor = Executors.newFixedThreadPool(totalCount);
         ExecutorService executor = Executors.newFixedThreadPool(totalCount);
         try {
         try {
             // prior 池并行拉取
             // prior 池并行拉取
             List<Future<List<VideoContentItemVO>>> futures = new ArrayList<>(totalCount);
             List<Future<List<VideoContentItemVO>>> futures = new ArrayList<>(totalCount);
             for (PriorPoolConfig cfg : PRIOR_POOL_CONFIGS) {
             for (PriorPoolConfig cfg : PRIOR_POOL_CONFIGS) {
                 futures.add(executor.submit(cfg.scene
                 futures.add(executor.submit(cfg.scene
-                        ? () -> fetchPriorSceneCandidates(param, user, DEMAND_CANDIDATE_LIMIT, cfg.dimension, cfg.demandType, cfg.matchMethod)
-                        : () -> fetchPriorPool(param, user, DEMAND_CANDIDATE_LIMIT, cfg.dimension, cfg.demandType, cfg.matchMethod)));
+                        ? () -> fetchPriorSceneCandidates(param, user, DEMAND_CANDIDATE_LIMIT, channel, dt, cfg.dimension, cfg.demandType, cfg.matchMethod)
+                        : () -> fetchPriorPool(param, user, DEMAND_CANDIDATE_LIMIT, channel, dt, cfg.dimension, cfg.demandType, cfg.matchMethod)));
             }
             }
             // posterior + hot
             // posterior + hot
             Future<List<VideoContentItemVO>> fPosterior = executor.submit(
             Future<List<VideoContentItemVO>> fPosterior = executor.submit(
-                    () -> fetchPosteriorCandidates(param, user, DEMAND_CANDIDATE_LIMIT));
+                    () -> fetchPosteriorCandidates(param, user, DEMAND_CANDIDATE_LIMIT, channel, dt));
             Future<List<VideoContentItemVO>> fHot = executor.submit(
             Future<List<VideoContentItemVO>> fHot = executor.submit(
                     () -> fetchHotCandidates(param, user, HOT_CANDIDATE_LIMIT));
                     () -> fetchHotCandidates(param, user, HOT_CANDIDATE_LIMIT));
             futures.add(fPosterior);
             futures.add(fPosterior);
@@ -987,9 +990,8 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
      * 3. 输出顺序按 sceneSumRov DESC,相同再按 total_rov DESC 兜底
      * 3. 输出顺序按 sceneSumRov DESC,相同再按 total_rov DESC 兜底
      */
      */
     private List<VideoContentItemVO> fetchPriorSceneCandidates(VideoContentListParam param, ContentPlatformAccount user, int limit,
     private List<VideoContentItemVO> fetchPriorSceneCandidates(VideoContentListParam param, ContentPlatformAccount user, int limit,
+                                                               DemandChannelEnum channel, String dt,
                                                                PriorDimensionEnum dimension, DemandTypeEnum demandType, DemandMatchMethodEnum matchMethod) {
                                                                PriorDimensionEnum dimension, DemandTypeEnum demandType, DemandMatchMethodEnum matchMethod) {
-        DemandChannelEnum channel = resolveChannelName(param);
-        String dt = demandVideoMapperExt.getMaxDt(channel == null ? null : channel.getValue());
         if (!StringUtils.hasText(dt)) {
         if (!StringUtils.hasText(dt)) {
             return new ArrayList<>();
             return new ArrayList<>();
         }
         }
@@ -1050,9 +1052,8 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
      * 6. 截断到 limit
      * 6. 截断到 limit
      */
      */
     private List<VideoContentItemVO> fetchPriorPool(VideoContentListParam param, ContentPlatformAccount user, int limit,
     private List<VideoContentItemVO> fetchPriorPool(VideoContentListParam param, ContentPlatformAccount user, int limit,
+                                                    DemandChannelEnum channel, String dt,
                                                     PriorDimensionEnum dimension, DemandTypeEnum demandType, DemandMatchMethodEnum matchMethod) {
                                                     PriorDimensionEnum dimension, DemandTypeEnum demandType, DemandMatchMethodEnum matchMethod) {
-        DemandChannelEnum channel = resolveChannelName(param);
-        String dt = demandVideoMapperExt.getMaxDt(channel == null ? null : channel.getValue());
         if (!StringUtils.hasText(dt)) {
         if (!StringUtils.hasText(dt)) {
             return new ArrayList<>();
             return new ArrayList<>();
         }
         }
@@ -1135,9 +1136,8 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
      * 按 demand_content_id 分组,组按 total_rov DESC、组内 score DESC 取前 K;
      * 按 demand_content_id 分组,组按 total_rov DESC、组内 score DESC 取前 K;
      * 跨组用 video_id + 归一化标题去重,截到 limit。
      * 跨组用 video_id + 归一化标题去重,截到 limit。
      */
      */
-    private List<VideoContentItemVO> fetchPosteriorCandidates(VideoContentListParam param, ContentPlatformAccount user, int limit) {
-        DemandChannelEnum channel = resolveChannelName(param);
-        String dt = demandVideoMapperExt.getMaxDt(channel == null ? null : channel.getValue());
+    private List<VideoContentItemVO> fetchPosteriorCandidates(VideoContentListParam param, ContentPlatformAccount user, int limit,
+                                                              DemandChannelEnum channel, String dt) {
         if (!StringUtils.hasText(dt)) {
         if (!StringUtils.hasText(dt)) {
             return new ArrayList<>();
             return new ArrayList<>();
         }
         }

+ 2 - 2
api-module/src/main/resources/mapper/contentplatform/ext/ContentPlatformDemandVideoMapperExt.xml

@@ -101,9 +101,9 @@
     <select id="selectChannelNameByGh" resultType="java.lang.String">
     <select id="selectChannelNameByGh" resultType="java.lang.String">
         SELECT channel_name
         SELECT channel_name
         FROM content_platform_demand_video
         FROM content_platform_demand_video
-        WHERE dt = #{dt}
-          AND channel_level3 = #{ghName}
+        WHERE channel_level3 = #{ghName}
           AND status = 1
           AND status = 1
+        ORDER BY dt DESC
         LIMIT 1
         LIMIT 1
     </select>
     </select>