|
@@ -9,7 +9,9 @@ import com.tzld.piaoquan.recommend.server.gen.common.Result;
|
|
|
import com.tzld.piaoquan.recommend.server.gen.common.TabProto;
|
|
import com.tzld.piaoquan.recommend.server.gen.common.TabProto;
|
|
|
import com.tzld.piaoquan.recommend.server.gen.tab.TabRequest;
|
|
import com.tzld.piaoquan.recommend.server.gen.tab.TabRequest;
|
|
|
import com.tzld.piaoquan.recommend.server.gen.tab.TabResponse;
|
|
import com.tzld.piaoquan.recommend.server.gen.tab.TabResponse;
|
|
|
|
|
+import com.tzld.piaoquan.recommend.server.model.RecommendParam;
|
|
|
import com.tzld.piaoquan.recommend.server.model.TabParam;
|
|
import com.tzld.piaoquan.recommend.server.model.TabParam;
|
|
|
|
|
+import com.tzld.piaoquan.recommend.server.model.Video;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -51,7 +53,9 @@ public class TabService {
|
|
|
"71", "81", "82"
|
|
"71", "81", "82"
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- private static final String redisKeyPrefox = "personalized_tab_candidate:";
|
|
|
|
|
|
|
+ private static final String personalizationTabCondidateFormat = "personalized_tab_candidate:%s";
|
|
|
|
|
+
|
|
|
|
|
+ private static final String userInvalidTabCache = "user:invalid:tab:cache:%s";
|
|
|
|
|
|
|
|
private static final String PERSONALIZATION_TAB_SEPARATOR = "&";
|
|
private static final String PERSONALIZATION_TAB_SEPARATOR = "&";
|
|
|
|
|
|
|
@@ -88,12 +92,13 @@ public class TabService {
|
|
|
return tabProtos;
|
|
return tabProtos;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String key = redisKeyPrefox + tabParam.getUnionId();
|
|
|
|
|
|
|
+ String key = String.format(personalizationTabCondidateFormat, tabParam.getUnionId());
|
|
|
String value = redisTemplate.opsForValue().get(key);
|
|
String value = redisTemplate.opsForValue().get(key);
|
|
|
if (StringUtils.isBlank(value)) {
|
|
if (StringUtils.isBlank(value)) {
|
|
|
log.error("unionId is not exist");
|
|
log.error("unionId is not exist");
|
|
|
return tabProtos;
|
|
return tabProtos;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
List<List<String>> tabCollect = Arrays.stream(value.split("\t"))
|
|
List<List<String>> tabCollect = Arrays.stream(value.split("\t"))
|
|
|
.map(i -> Arrays.asList(i.split(PERSONALIZATION_TAB_SEPARATOR)))
|
|
.map(i -> Arrays.asList(i.split(PERSONALIZATION_TAB_SEPARATOR)))
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
@@ -114,7 +119,14 @@ public class TabService {
|
|
|
tabProtos.addAll(0, returnCate2Tab);
|
|
tabProtos.addAll(0, returnCate2Tab);
|
|
|
tabProtos.addAll(0, shareCate2Tab);
|
|
tabProtos.addAll(0, shareCate2Tab);
|
|
|
tabProtos.addAll(0, profileTab);
|
|
tabProtos.addAll(0, profileTab);
|
|
|
- return tabProtos.subList(0, Math.min(tabProtos.size(), personalizationTabSize));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ String invalidTabCacheKey = String.format(userInvalidTabCache, tabParam.getUnionId());
|
|
|
|
|
+ Set<String> invalidTabCache = Optional.ofNullable(redisTemplate.opsForSet().members(invalidTabCacheKey)).orElse(new HashSet<>());
|
|
|
|
|
+
|
|
|
|
|
+ return tabProtos
|
|
|
|
|
+ .stream().filter(i -> !invalidTabCache.contains(i.getKey()))
|
|
|
|
|
+ .limit(Math.min(tabProtos.size(), personalizationTabSize))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<TabProto> buildTabProto(List<String> tabNames, TabSource source, TabType type) {
|
|
private List<TabProto> buildTabProto(List<String> tabNames, TabSource source, TabType type) {
|
|
@@ -176,4 +188,20 @@ public class TabService {
|
|
|
return CHINA_PROVINCE_CODE_PREFIXES.contains(provinceCode.substring(0, 2));
|
|
return CHINA_PROVINCE_CODE_PREFIXES.contains(provinceCode.substring(0, 2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void updateUserTabCache(RecommendParam param, List<Video> videos) {
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ if (Objects.isNull(param.getTab()) || StringUtils.isBlank(param.getTab().getKey())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ int size = param.getSize();
|
|
|
|
|
+ if (CollectionUtils.isEmpty(videos) || videos.size() < size) {
|
|
|
|
|
+ String key = String.format(userInvalidTabCache, param.getUnionId());
|
|
|
|
|
+ redisTemplate.opsForSet().add(key, param.getTab().getKey());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("updateUserTabCache error", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|