丁云鹏 преди 1 година
родител
ревизия
febb5d5745

+ 0 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -133,8 +133,6 @@ public class RecommendService {
         updateLastVideoCache(request, param, videos);
         updateFlowPoolCache(request, param, videos);
 
-        // 更新视频限流逻辑:redis没有这个key,而且代码中无引用
-
     }
 
     private void updateFlowPoolCache(HomepageRecommendRequest request, HomepageRecommendParam param,

+ 41 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/flowpool/FlowPoolService.java

@@ -1,7 +1,9 @@
 package com.tzld.piaoquan.recommend.server.service.flowpool;
 
+import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.ThreadPoolFactory;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -105,8 +107,6 @@ public class FlowPoolService {
         }
 
         Map<Long, Integer> result = getDistributeCount(videoFlowPoolMap);
-
-
         // 处理脏数据:分发数<0
         Map<Long, String> dirties = videoFlowPoolMap.entrySet().stream()
                 .filter(e -> result.get(e.getKey()) <= 0)
@@ -146,10 +146,7 @@ public class FlowPoolService {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return Collections.emptyMap();
         }
-
         Map<Long, Integer> result = getDistributeCount(videoFlowPoolMap);
-
-
         // 处理脏数据:分发数<0
         Map<Long, String> dirties = videoFlowPoolMap.entrySet().stream()
                 .filter(e -> result.get(e.getKey()) <= 0)
@@ -185,4 +182,43 @@ public class FlowPoolService {
         });
     }
 
+    public void updateLocalDistributeCountWithLevel(List<Video> videos) {
+        if (CollectionUtils.isEmpty(videos)) {
+            return;
+        }
+        Map<Long, String> removeMap = updateDistributeCount(videos);
+
+        asyncDelLocalDistributeCountWithLevel(removeMap);
+
+    }
+
+    private Map<Long, String> updateDistributeCount(List<Video> videos) {
+        Map<Long, String> removeMap = new HashMap<>();
+        videos.stream().forEach(v -> {
+            String key = String.format(localDistributeCountFormat, v.getVideoId(), v.getFlowPool());
+            Long count = redisTemplate.opsForValue().decrement(key);
+            if (count <= 0) {
+                removeMap.put(v.getVideoId(), v.getFlowPool());
+            }
+        });
+        return removeMap;
+    }
+
+    public void updateLocalDistributeCountWithLevelScore(List<Video> videos) {
+        if (CollectionUtils.isEmpty(videos)) {
+            return;
+        }
+        Map<Long, String> removeMap = updateDistributeCount(videos);
+
+        asyncDelLocalDistributeCountWithLevelScore(removeMap);
+    }
+
+    public void updateLocalDistributeCount(List<Video> videos) {
+        if (CollectionUtils.isEmpty(videos)) {
+            return;
+        }
+        Map<Long, String> removeMap = updateDistributeCount(videos);
+
+        asyncDelLocalDistributeCountWithScore(removeMap);
+    }
 }