From ad021691bb5296f203ddeaba41241d8ca1317414 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Tue, 17 Sep 2024 20:50:29 +0100 Subject: 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 Change-Id: I80d97d8cc24372eed70626ed840cad985cbe0a4b --- .../main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java | 3 +-- .../src/main/java/org/onap/cps/utils/PrefixResolver.java | 13 ------------- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'cps-service/src/main/java/org/onap') 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> prefixResolver(final Anchor anchor, final Collection dataNodes) { final List> 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 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 @@ -54,19 +54,6 @@ public class PrefixResolver { private final IMap 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. * -- cgit 1.2.3-korg