diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-14 15:39:19 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-14 15:39:19 +0200 |
commit | e43172a0f87fffc7ac12c49a7f6111123d42a0b6 (patch) | |
tree | 24173fdc071321221c3dd8aa3772d60ba307f005 /config-model | |
parent | 23087af2efb26eebe0ad2fbd383b1a3bd6ee9bfc (diff) |
Cache list that is potentially hard to compute.
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index 64e3e794429..939ee37d328 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -107,6 +107,7 @@ public class RankProfile implements Cloneable { private Map<String, RankingExpressionFunction> functions = new LinkedHashMap<>(); // This cache must be invalidated every time modifications are done to 'functions'. private Map<String, RankingExpressionFunction> allFunctionsCached = null; + private List<ExpressionFunction> allExpressionFunctionCached = null; private Map<Reference, TensorType> inputFeatures = new LinkedHashMap<>(); @@ -677,11 +678,22 @@ public class RankProfile implements Cloneable { } /** Returns an unmodifiable snapshot of the functions in this */ public Map<String, RankingExpressionFunction> getFunctions() { + updateCachedFunctions(); + return allFunctionsCached; + } + private List<ExpressionFunction> getExpressionFunctions() { + updateCachedFunctions(); + return allExpressionFunctionCached; + } + private void updateCachedFunctions() { if (needToUpdateFunctionCache()) { allFunctionsCached = gatherAllFunctions(); + allExpressionFunctionCached = allFunctionsCached.values().stream() + .map(RankingExpressionFunction::function) + .collect(Collectors.toList()); } - return allFunctionsCached; } + private Map<String, RankingExpressionFunction> gatherAllFunctions() { if (functions.isEmpty() && getInherited() == null) return Collections.emptyMap(); if (functions.isEmpty()) return getInherited().getFunctions(); @@ -914,10 +926,7 @@ public class RankProfile implements Cloneable { } public MapEvaluationTypeContext typeContext(QueryProfileRegistry queryProfiles, Map<Reference, TensorType> featureTypes) { - MapEvaluationTypeContext context = new MapEvaluationTypeContext(getFunctions().values().stream() - .map(RankingExpressionFunction::function) - .collect(Collectors.toList()), - featureTypes); + MapEvaluationTypeContext context = new MapEvaluationTypeContext(getExpressionFunctions(), featureTypes); // Add small and large constants, respectively getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type())); |