aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-09-17 20:50:29 +0100
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-09-24 10:48:42 +0100
commitad021691bb5296f203ddeaba41241d8ca1317414 (patch)
tree0d54a47ae33d284078bc31238e0f31d4155fb0f9 /cps-service/src
parent06391e2c0b13064caa643bd9f44e773eaeeb2631 (diff)
Reduce anchor lookups related to PrefixResolver (CPS-2417 #1)
Instead of looking up same Anchor many times inside a for-loop, do it once outside the loop. This greatly improves performance in some cases, such as v2 GET API: - /cps/api/v2/dataspaces/{dataspace}/anchors/{anchor}/node Testing shows 3x faster response time. Issue-ID: CPS-2417 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I80d97d8cc24372eed70626ed840cad985cbe0a4b
Diffstat (limited to 'cps-service/src')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java3
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java13
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy12
3 files changed, 7 insertions, 21 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index 951770b053..eed4f09bf0 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -400,8 +400,7 @@ public class CpsDataServiceImpl implements CpsDataService {
private List<Map<String, Object>> prefixResolver(final Anchor anchor, final Collection<DataNode> dataNodes) {
final List<Map<String, Object>> prefixToDataNodes = new ArrayList<>(dataNodes.size());
for (final DataNode dataNode: dataNodes) {
- final String prefix = prefixResolver
- .getPrefix(anchor.getDataspaceName(), anchor.getName(), dataNode.getXpath());
+ final String prefix = prefixResolver.getPrefix(anchor, dataNode.getXpath());
final Map<String, Object> prefixToDataNode = DataMapUtils.toDataMapWithIdentifier(dataNode, prefix);
prefixToDataNodes.add(prefixToDataNode);
}
diff --git a/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java b/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java
index 35dc7347b2..93fb72864f 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java
@@ -55,19 +55,6 @@ public class PrefixResolver {
private final IMap<String, AnchorDataCacheEntry> anchorDataCache;
/**
- * Get the module prefix for the given xpath for a dataspace and anchor name.
- *
- * @param dataspaceName the name of the dataspace
- * @param anchorName the name of the anchor the xpath belongs to
- * @param xpath the xpath to prefix a prefix for
- * @return the prefix of the module the top level element of given xpath
- */
- public String getPrefix(final String dataspaceName, final String anchorName, final String xpath) {
- final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
- return getPrefix(anchor, xpath);
- }
-
- /**
* Get the module prefix for the given xpath under the given anchor.
*
* @param anchor the anchor the xpath belong to
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy
index b975de6555..5ef584a0b8 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy
@@ -48,10 +48,10 @@ class PrefixResolverSpec extends Specification {
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+ def anchor = new Anchor(dataspaceName: 'testDataspace', name: 'testAnchor')
+
def setup() {
- given: 'an anchor for the test-tree model'
- def anchor = new Anchor(dataspaceName: 'testDataspace', name: 'testAnchor')
- and: 'the system can get this anchor'
+ given: 'the system can get the anchor'
mockCpsAnchorService.getAnchor('testDataspace', 'testAnchor') >> anchor
and: 'the schema source cache contains the schema context for the test-tree module'
mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
@@ -59,7 +59,7 @@ class PrefixResolverSpec extends Specification {
def 'get xpath prefix using node schema context'() {
when: 'the prefix of the yang module is retrieved'
- def result = objectUnderTest.getPrefix('testDataspace', 'testAnchor', xpath)
+ def result = objectUnderTest.getPrefix(anchor, xpath)
then: 'the expected prefix is returned'
result == expectedPrefix
and: 'the cache is updated for the given anchor with a map of prefixes per top level container (just one one this case)'
@@ -90,7 +90,7 @@ class PrefixResolverSpec extends Specification {
mockAnchorDataCache.containsKey('testAnchor') >> true
mockAnchorDataCache.get('testAnchor') >> anchorDataCacheEntry
when: 'the prefix of the yang module is retrieved'
- def result = objectUnderTest.getPrefix('testDataspace', 'testAnchor', '/test-tree')
+ def result = objectUnderTest.getPrefix(anchor, '/test-tree')
then: 'the expected prefix is returned'
result == expectedPrefix
and: 'schema source cache is not used (i.e. no need to build schema context)'
@@ -108,7 +108,7 @@ class PrefixResolverSpec extends Specification {
mockAnchorDataCache.containsKey('testAnchor') >> true
mockAnchorDataCache.get('testAnchor') >> anchorDataCacheEntry
when: 'the prefix of the yang module is retrieved'
- def result = objectUnderTest.getPrefix('testDataspace', 'testAnchor', '/test-tree')
+ def result = objectUnderTest.getPrefix(anchor, '/test-tree')
then: 'the expected prefix is returned'
result == 'tree'
and: 'schema source cache is used (i.e. need to build schema context)'