Selaa lähdekoodia

support compress

丁云鹏 2 kuukautta sitten
vanhempi
commit
813494a1dd

+ 5 - 19
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/service/FeatureV2Service.java

@@ -12,7 +12,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -29,16 +28,9 @@ public class FeatureV2Service {
     @Autowired
     private RedisTemplate<String, String> redisTemplate;
 
-    @ApolloJsonValue("${dts.config.v2:}")
-    private List<DTSConfig> dtsConfigs;
-
     @ApolloJsonValue("${dts.config:}")
     private List<DTSConfig> newDtsConfigs;
 
-    @Value("${compress.switch: false}")
-    private boolean compressSwitch;
-
-
     public MultiGetFeatureResponse multiGetFeature(MultiGetFeatureRequest request) {
         if (request.getFeatureKeyCount() == 0) {
             return MultiGetFeatureResponse.newBuilder()
@@ -48,14 +40,8 @@ public class FeatureV2Service {
         // 目前都在一个Redis,所以放在一个list简化处理
         List<String> redisKeys = CommonCollectionUtils.toList(request.getFeatureKeyList(), fk -> redisKey(fk));
         List<String> values = redisTemplate.opsForValue().multiGet(redisKeys);
-        if (compressSwitch) {
-            // 兼容老的数据
-            if (redisKeys.get(0).startsWith("snappy")) {
-                values = CommonCollectionUtils.toList(values, CompressionUtil::snappyDecompress);
-            } else {
-                log.info("请求未压缩数据 {}", redisKeys.get(0));
-            }
-        }
+        // 兼容老的数据
+        values = CommonCollectionUtils.toList(values, CompressionUtil::snappyDecompress);
 
         //log.info("feature key {} value {}", JSONUtils.toJson(redisKeys), JSONUtils.toJson(values));
 
@@ -71,9 +57,9 @@ public class FeatureV2Service {
     // Note:写入和读取的key生成规则应保持一致
     private String redisKey(FeatureKeyProto fk) {
 
-        Optional<DTSConfig> optional = (compressSwitch ? newDtsConfigs : dtsConfigs)
-                .stream().filter(c -> c.getOdps() != null && StringUtils.equals(c.getOdps().getTable(),
-                        fk.getTableName())).findFirst();
+        Optional<DTSConfig> optional = newDtsConfigs.stream()
+                .filter(c -> c.getOdps() != null && StringUtils.equals(c.getOdps().getTable(), fk.getTableName()))
+                .findFirst();
         if (!optional.isPresent()) {
             log.error("table {} not config", fk.getTableName());
             return "";