|
|
@@ -17,6 +17,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
@@ -28,6 +29,9 @@ import java.util.*;
|
|
|
@Slf4j
|
|
|
public class FeatureService {
|
|
|
|
|
|
+ @Value("${feature.service.optimize.switch}")
|
|
|
+ private Boolean featureServiceOptimizeSwtich;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FeatureV2RemoteService remoteService;
|
|
|
|
|
|
@@ -399,7 +403,7 @@ public class FeatureService {
|
|
|
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);
|
|
|
Feature feature = new Feature();
|
|
|
result.forEach((key, value) -> {
|
|
|
@@ -410,18 +414,22 @@ public class FeatureService {
|
|
|
Map<String, String> colMap = JSONUtils.fromJson(value, new TypeToken<Map<String, String>>() {
|
|
|
}, 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) {
|
|
|
case "v":
|
|
|
String vid = uk[2];
|
|
|
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);
|
|
|
break;
|
|
|
case "u":
|
|
|
- feature.getUserFeature().put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
|
|
|
- }, Collections.emptyMap()));
|
|
|
+ feature.getUserFeature().put(table, featureMap);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -496,7 +504,7 @@ public class FeatureService {
|
|
|
.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()
|
|
|
.setUniqueKey(String.format(kvUkFormat, table, uniqKey))
|
|
|
.setTableName(table);
|