Przeglądaj źródła

feat:特征服务优化适配

zhaohaipeng 1 tydzień temu
rodzic
commit
7e92afb349

+ 1 - 0
.gitignore

@@ -62,3 +62,4 @@ recommend-server/logs
 LOG_PATH_IS_UNDEFINED
 LOG_PATH_IS_UNDEFINED
 datalog
 datalog
 word2vec.bin
 word2vec.bin
+recommend-server-service/recommend-server/logs

+ 15 - 7
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/FeatureService.java

@@ -17,6 +17,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.util.*;
 import java.util.*;
@@ -28,6 +29,9 @@ import java.util.*;
 @Slf4j
 @Slf4j
 public class FeatureService {
 public class FeatureService {
 
 
+    @Value("${feature.service.optimize.switch}")
+    private Boolean featureServiceOptimizeSwtich;
+
     @Autowired
     @Autowired
     private FeatureV2RemoteService remoteService;
     private FeatureV2RemoteService remoteService;
 
 
@@ -399,7 +403,7 @@ public class FeatureService {
         return feature.getUserFeature().getOrDefault("alg_recsys_user_social_recall_feature_day", new HashMap<>());
         return feature.getUserFeature().getOrDefault("alg_recsys_user_social_recall_feature_day", new HashMap<>());
     }
     }
 
 
-    private Feature getFeatureByProto(List<FeatureKeyProto> protos) {
+    public Feature getFeatureByProto(List<FeatureKeyProto> protos) {
         Map<String, String> result = remoteService.getFeature(protos);
         Map<String, String> result = remoteService.getFeature(protos);
         Feature feature = new Feature();
         Feature feature = new Feature();
         result.forEach((key, value) -> {
         result.forEach((key, value) -> {
@@ -410,18 +414,22 @@ public class FeatureService {
                 Map<String, String> colMap = JSONUtils.fromJson(value, new TypeToken<Map<String, String>>() {
                 Map<String, String> colMap = JSONUtils.fromJson(value, new TypeToken<Map<String, String>>() {
                 }, Collections.emptyMap());
                 }, Collections.emptyMap());
 
 
-                String featureStr = colMap.get("feature");
+                Map<String, String> featureMap = new HashMap<>();
+                if (Boolean.TRUE.equals(featureServiceOptimizeSwtich)) {
+                    featureMap = colMap;
+                } else {
+                    featureMap = JSONUtils.fromJson(colMap.get("feature"), new TypeToken<Map<String, String>>() {
+                    }, Collections.emptyMap());
+                }
                 switch (prefix) {
                 switch (prefix) {
                     case "v":
                     case "v":
                         String vid = uk[2];
                         String vid = uk[2];
                         Map<String, Map<String, String>> tableFeatureMap = feature.getVideoFeature().getOrDefault(vid, new HashMap<>());
                         Map<String, Map<String, String>> tableFeatureMap = feature.getVideoFeature().getOrDefault(vid, new HashMap<>());
-                        tableFeatureMap.put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
-                        }, Collections.emptyMap()));
+                        tableFeatureMap.put(table, featureMap);
                         feature.getVideoFeature().put(vid, tableFeatureMap);
                         feature.getVideoFeature().put(vid, tableFeatureMap);
                         break;
                         break;
                     case "u":
                     case "u":
-                        feature.getUserFeature().put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
-                        }, Collections.emptyMap()));
+                        feature.getUserFeature().put(table, featureMap);
                         break;
                         break;
                     default:
                     default:
                         break;
                         break;
@@ -496,7 +504,7 @@ public class FeatureService {
                 .build();
                 .build();
     }
     }
 
 
-    private FeatureKeyProto genWithKeyMap(String table, String uniqKey, Map<String, String> map) {
+    public FeatureKeyProto genWithKeyMap(String table, String uniqKey, Map<String, String> map) {
         FeatureKeyProto.Builder builder = FeatureKeyProto.newBuilder()
         FeatureKeyProto.Builder builder = FeatureKeyProto.newBuilder()
                 .setUniqueKey(String.format(kvUkFormat, table, uniqKey))
                 .setUniqueKey(String.format(kvUkFormat, table, uniqKey))
                 .setTableName(table);
                 .setTableName(table);

+ 27 - 0
recommend-server-service/src/test/java/com/tzld/piaoquan/recommend/server/service/FeatureServiceTest.java

@@ -0,0 +1,27 @@
+package com.tzld.piaoquan.recommend.server.service;
+
+import com.google.common.collect.ImmutableMap;
+import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@SpringBootTest
+public class FeatureServiceTest {
+
+    @Autowired
+    private FeatureService featureService;
+
+    @Test
+    public void featureV3OptimizeTest() {
+
+        List<FeatureKeyProto> protos = new ArrayList<>();
+        protos.add(featureService.genWithKeyMap("alg_videoid_feature", "10035427", ImmutableMap.of("videoid", "68781839")));
+
+        System.out.println(featureService.getFeatureByProto(protos));
+    }
+
+}