|
@@ -1,13 +1,17 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service.filter.strategy;
|
|
|
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
import com.google.common.cache.CacheLoader;
|
|
|
import com.google.common.cache.LoadingCache;
|
|
|
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.repository.WxVideoTagRel;
|
|
|
+import com.tzld.piaoquan.recommend.server.repository.WxVideoTagRelRepository;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterStrategy;
|
|
|
+import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -22,6 +26,7 @@ import org.springframework.data.redis.core.SessionCallback;
|
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -36,9 +41,11 @@ public class VideoSourceTypeStrategy implements FilterStrategy {
|
|
|
@Qualifier("redisTemplate")
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private WxVideoStatusRepository wxVideoStatusRepository;
|
|
|
|
|
|
+
|
|
|
private final String keyFormat = "video:uid:%s";
|
|
|
|
|
|
public static final String NOT_USER_UPLOAD_USER_KEY = "not:user:upload:user";
|
|
@@ -58,9 +65,35 @@ public class VideoSourceTypeStrategy implements FilterStrategy {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WxVideoTagRelRepository repository;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${user.upload.exclude.tagids:[]}")
|
|
|
+ private List<Long> userUploadExcludeTagIds;
|
|
|
+
|
|
|
+ private String userUploadExcludeVideoCacheKey = "user.upload.exclude.video";
|
|
|
+ // 内存持久保存不淘汰
|
|
|
+ private LoadingCache<String, Set<Long>> userUploadExcludeVideoCache = CacheBuilder.newBuilder()
|
|
|
+ .maximumSize(10)
|
|
|
+ .refreshAfterWrite(60, TimeUnit.SECONDS)
|
|
|
+ .expireAfterWrite(60, TimeUnit.SECONDS)
|
|
|
+ .expireAfterAccess(60, TimeUnit.SECONDS)
|
|
|
+ .build(new CacheLoader<String, Set<Long>>() {
|
|
|
+ @Override
|
|
|
+ public Set<Long> load(String key) {
|
|
|
+ List<WxVideoTagRel> rels = repository.findAllByTagIdIn(userUploadExcludeTagIds);
|
|
|
+ return CommonCollectionUtils.toSet(rels, WxVideoTagRel::getVideoId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ Set<Long> data = userUploadExcludeVideoCache.getUnchecked(userUploadExcludeVideoCacheKey);
|
|
|
+ log.info("userUploadExcludeVideoCache size {}", data.size());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Long> filter(FilterParam param) {
|
|
|
-
|
|
|
if (param == null) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
@@ -114,15 +147,16 @@ public class VideoSourceTypeStrategy implements FilterStrategy {
|
|
|
}
|
|
|
|
|
|
Set<String> notUserUploadUserIds = notUserUploadUserCache.getUnchecked(NOT_USER_UPLOAD_USER_KEY);
|
|
|
+ Set<Long> data = userUploadExcludeVideoCache.getUnchecked(userUploadExcludeVideoCacheKey);
|
|
|
|
|
|
List<Long> videoIds = param.getVideoIds().stream()
|
|
|
- .filter(l -> vid2UidMap.containsKey(l)
|
|
|
- && notUserUploadUserIds.contains(vid2UidMap.get(l)))
|
|
|
+ .filter(l -> data.contains(l)
|
|
|
+ || (vid2UidMap.containsKey(l) && notUserUploadUserIds.contains(vid2UidMap.get(l))))
|
|
|
.collect(Collectors.toList());
|
|
|
- log.info("VideoSourceTypeStrategy \t param={} \t vid2Uid={} \t before={} \t " +
|
|
|
+
|
|
|
+ log.info("VideoSourceTypeStrategy \t param={} \t before={} \t " +
|
|
|
"after={}",
|
|
|
JSONUtils.toJson(param),
|
|
|
- JSONUtils.toJson(vid2UidMap),
|
|
|
JSONUtils.toJson(param.getVideoIds()),
|
|
|
JSONUtils.toJson(videoIds));
|
|
|
|