丁云鹏 1 rok temu
rodzic
commit
ae0cd8d051

+ 11 - 9
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/AllowListStrategy.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.recommend.server.service.filter.strategy;
 
+import com.google.common.base.Stopwatch;
 import com.google.common.collect.Lists;
 import com.google.common.hash.Hashing;
 import com.tzld.piaoquan.recommend.server.common.enums.AppTypeEnum;
@@ -33,7 +34,7 @@ public class AllowListStrategy implements FilterStrategy {
     @Override
     // TODO 未找到优化方法 暂时保留原代码
     public List<Long> filter(FilterParam param) {
-
+        Stopwatch stopwatch = Stopwatch.createStarted();
         if (param == null
                 || CollectionUtils.isEmpty(param.getVideoIds())) {
             return Collections.emptyList();
@@ -66,6 +67,7 @@ public class AllowListStrategy implements FilterStrategy {
                 }
             }
         }
+        log.info("AllowListStrategy cost {} ms", stopwatch.elapsed().toMillis());
         if (CollectionUtils.isEmpty(retainVideoIds)) {
             return Collections.emptyList();
         }
@@ -81,14 +83,14 @@ public class AllowListStrategy implements FilterStrategy {
             int newIdx = Math.abs(Hashing.murmur3_32().hashLong(videoId).asInt()) % 100;
             String newPrefix = VIDEO_ALLOW_LIST_BITMAP_KEY_SET_PREFIX + newIdx;
             Boolean result = redisTemplate.opsForSet().isMember(newPrefix, String.valueOf(videoId));
-            // 兼容旧 key
-            if (Objects.equals(1, mvalCompatible) && !result) {
-                int idx = Math.abs(Hashing.murmur3_32().hashLong(videoId).asInt()) % 10;
-                result = redisTemplate.opsForValue().getBit(VIDEO_ALLOW_LIST_BITMAP_KEY_PREFIX + idx, videoId);
-            }
-            if (Objects.equals(1, mvalCompatible) && !result) {
-                result = redisTemplate.opsForValue().getBit(VIDEO_ALLOW_LIST_BITMAP_KEY, videoId);
-            }
+//            // 兼容旧 key apollo配置0 所以删除
+//            if (Objects.equals(1, mvalCompatible) && !result) {
+//                int idx = Math.abs(Hashing.murmur3_32().hashLong(videoId).asInt()) % 10;
+//                result = redisTemplate.opsForValue().getBit(VIDEO_ALLOW_LIST_BITMAP_KEY_PREFIX + idx, videoId);
+//            }
+//            if (Objects.equals(1, mvalCompatible) && !result) {
+//                result = redisTemplate.opsForValue().getBit(VIDEO_ALLOW_LIST_BITMAP_KEY, videoId);
+//            }
             return result;
         } catch (Exception e) {
             log.error("isMemberOfVideoAllowList error {}", videoId, e);

+ 5 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/RecommendStatusStrategy.java

@@ -1,10 +1,12 @@
 package com.tzld.piaoquan.recommend.server.service.filter.strategy;
 
+import com.google.common.base.Stopwatch;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoStatus;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoStatusRepository;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterStrategy;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -25,6 +27,7 @@ import java.util.stream.Collectors;
  * @author dyp
  */
 @Component
+@Slf4j
 public class RecommendStatusStrategy implements FilterStrategy {
     @Autowired
     private RedisTemplate<String, String> redisTemplate;
@@ -38,7 +41,7 @@ public class RecommendStatusStrategy implements FilterStrategy {
 
     @Override
     public List<Long> filter(FilterParam param) {
-
+        Stopwatch stopwatch = Stopwatch.createStarted();
         if (param == null
                 || CollectionUtils.isEmpty(param.getVideoIds())) {
             return Collections.emptyList();
@@ -87,7 +90,7 @@ public class RecommendStatusStrategy implements FilterStrategy {
             }
         }
 
-
+        log.info("recommendStatusStrategy filter cost: {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         return param.getVideoIds().stream()
                 .filter(id -> recommendStatusMap.containsKey(id) && recommendStatusMap.get(id) == RECOMMEND_STATUS)
                 .collect(Collectors.toList());

+ 5 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/ViewedStrategy.java

@@ -1,8 +1,10 @@
 package com.tzld.piaoquan.recommend.server.service.filter.strategy;
 
+import com.google.common.base.Stopwatch;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterStrategy;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +27,7 @@ import java.util.stream.Collectors;
  * @author dyp
  */
 @Component
+@Slf4j
 public class ViewedStrategy implements FilterStrategy {
     @Autowired
     private RedisTemplate<String, String> redisTemplate;
@@ -36,6 +39,7 @@ public class ViewedStrategy implements FilterStrategy {
 
     @Override
     public List<Long> filter(FilterParam param) {
+        Stopwatch stopwatch = Stopwatch.createStarted();
         String user = StringUtils.isNotBlank(param.getUid()) ? param.getUid() : param.getMid();
         if (StringUtils.isBlank(user)) {
             return param.getVideoIds();
@@ -71,7 +75,7 @@ public class ViewedStrategy implements FilterStrategy {
                 });
             }
         }
-
+        log.info("ViewedStrategy filter cost: {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         if (CollectionUtils.isEmpty(viewedVideoIds)) {
             return param.getVideoIds();
         }