丁云鹏 1 年之前
父节点
当前提交
aaa9ac808b

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

@@ -15,12 +15,10 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -29,8 +27,6 @@ import java.util.concurrent.TimeUnit;
 @Component
 @Slf4j
 public class TagStrategy implements FilterStrategy {
-    @Autowired
-    private RedisTemplate<String, String> redisTemplate;
 
     @Autowired
     private WxVideoTagRelRepository repository;
@@ -55,13 +51,13 @@ public class TagStrategy implements FilterStrategy {
     @PostConstruct
     public void init() {
         if (StringUtils.isNotBlank(videoFilterTagIds)) {
-            Map<Long, Set<Long>> tmp = new ConcurrentHashMap<>();
+            // 只有涉政标签,用循环简化代码
             String[] tags = videoFilterTagIds.split(",");
             for (String tag : tags) {
                 if (StringUtils.isBlank(tag)) {
                     continue;
                 }
-                videoTagCache.get(NumberUtils.toLong(tag));
+                videoTagCache.getUnchecked(NumberUtils.toLong(tag));
             }
         }
     }
@@ -110,11 +106,11 @@ public class TagStrategy implements FilterStrategy {
         if (Objects.isNull(videoId) || videoId <= 0L || Objects.isNull(tagId) || tagId <= 0L) {
             return false;
         }
-        Set<Long> videosByTag = videoTagCache.get(tagId);
-        if (Objects.isNull(videosByTag) || videosByTag.isEmpty()) {
+        Set<Long> videos = videoTagCache.getUnchecked(tagId);
+        if (CollectionUtils.isEmpty(videos)) {
             return false;
         }
-        return videosByTag.contains(videoId);
+        return videos.contains(videoId);
     }
 
 }