|
|
@@ -29,6 +29,9 @@ public class PreViewedService {
|
|
|
@Qualifier("redisTemplate")
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExperimentService experimentService;
|
|
|
+
|
|
|
@ApolloJsonValue("${preview.exp.config:{}}")
|
|
|
private Map<String, Integer> preViewExpConfig;
|
|
|
|
|
|
@@ -48,7 +51,8 @@ public class PreViewedService {
|
|
|
// }
|
|
|
// });
|
|
|
|
|
|
- public void updateCache(int appType, String mid, List<Video> videos, Set<String> abExpCodes) {
|
|
|
+ public void updateCache(int appType, String mid, String rootSessionId,
|
|
|
+ List<Video> videos, Set<String> abExpCodes) {
|
|
|
if (StringUtils.isBlank(mid)
|
|
|
|| CollectionUtils.isEmpty(videos)) {
|
|
|
return;
|
|
|
@@ -60,20 +64,26 @@ public class PreViewedService {
|
|
|
}
|
|
|
String key = String.format(KEY_PRE_VIEWED_FORMAT, appType, mid);
|
|
|
|
|
|
- int expire = 30;
|
|
|
+ int expire = resolveExpireMinutes(appType, rootSessionId, abExpCodes);
|
|
|
+
|
|
|
+ redisTemplate.opsForSet().add(key, videoIds);
|
|
|
+ redisTemplate.expire(key, expire, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 遍历 preview.exp.config(expCode → minutes),用 judgeHitAlgoExp 判断是否命中(算法层)。
|
|
|
+ * judgeHitAlgoExp 同时覆盖 abExpCodes 通道和 root.session.id.exp.layer.config.算法 尾号通道。
|
|
|
+ * 都不命中 → 默认 30min。
|
|
|
+ */
|
|
|
+ private int resolveExpireMinutes(int appType, String rootSessionId, Set<String> abExpCodes) {
|
|
|
if (MapUtils.isNotEmpty(preViewExpConfig)) {
|
|
|
for (Map.Entry<String, Integer> entry : preViewExpConfig.entrySet()) {
|
|
|
- if (CommonCollectionUtils.contains(abExpCodes, entry.getKey())) {
|
|
|
- expire = entry.getValue() != null
|
|
|
- ? entry.getValue()
|
|
|
- : 30;
|
|
|
- break;
|
|
|
+ if (experimentService.judgeHitAlgoExp(appType, rootSessionId, abExpCodes, entry.getKey())) {
|
|
|
+ return entry.getValue() != null ? entry.getValue() : 30;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- redisTemplate.opsForSet().add(key, videoIds);
|
|
|
- redisTemplate.expire(key, expire, TimeUnit.MINUTES);
|
|
|
+ return 30;
|
|
|
}
|
|
|
|
|
|
public Set<Long> getVideoIds(int appType, String mid) {
|