diff options
author | kissand <andras.zoltan.kiss@est.tech> | 2022-09-23 13:49:05 +0200 |
---|---|---|
committer | Andras Zoltan Kiss <andras.zoltan.kiss@est.tech> | 2022-10-12 12:32:42 +0000 |
commit | d05c1d71f33c1d951d5a5196f6c206457431da9e (patch) | |
tree | 175b3ae4682d256dd971f046fcfd1169e5891a45 /cps-ri/src/main/java/org/onap | |
parent | c9ec915d7d16b88f53493c85928d463d070df472 (diff) |
Fix Id-searches endpoint performance degradation
- create more flexible control over fetch descendants
- add a new FETCH_DIRECT_CHILDREN_ONLY option to fetch descendants
options
- enabel create custom fetch descendants option
Reviewer: Toine, Joe, Priyank
Issue-ID: CPS-1216
Change-Id: I900b32e813367aa9566c1dec986b20f009d27203
Signed-off-by: kissand <andras.zoltan.kiss@est.tech>
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java index c13422dc4d..ebc851a443 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java @@ -22,8 +22,6 @@ package org.onap.cps.spi.impl; -import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; - import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import java.util.ArrayList; @@ -102,7 +100,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService @Override public void addMultipleLists(final String dataspaceName, final String anchorName, final String parentNodeXpath, - final Collection<Collection<DataNode>> newLists) { + final Collection<Collection<DataNode>> newLists) { final Collection<String> failedXpaths = new HashSet<>(); newLists.forEach(newList -> { try { @@ -119,7 +117,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } private void addNewChildDataNode(final String dataspaceName, final String anchorName, - final String parentNodeXpath, final DataNode newChild) { + final String parentNodeXpath, final DataNode newChild) { final FragmentEntity parentFragmentEntity = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath); final FragmentEntity newChildAsFragmentEntity = convertToFragmentWithAllDescendants(parentFragmentEntity.getDataspace(), @@ -134,7 +132,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } private void addChildrenDataNodes(final String dataspaceName, final String anchorName, final String parentNodeXpath, - final Collection<DataNode> newChildren) { + final Collection<DataNode> newChildren) { final FragmentEntity parentFragmentEntity = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath); final List<FragmentEntity> fragmentEntities = new ArrayList<>(newChildren.size()); try { @@ -154,7 +152,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } private void retrySavingEachChildIndividually(final String dataspaceName, final String anchorName, - final String parentNodeXpath, final Collection<DataNode> newChildren) { + final String parentNodeXpath, + final Collection<DataNode> newChildren) { final Collection<String> failedXpaths = new HashSet<>(); for (final DataNode newChild : newChildren) { try { @@ -191,7 +190,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService * @return a Fragment built from current DataNode */ private FragmentEntity convertToFragmentWithAllDescendants(final DataspaceEntity dataspaceEntity, - final AnchorEntity anchorEntity, final DataNode dataNodeToBeConverted) { + final AnchorEntity anchorEntity, + final DataNode dataNodeToBeConverted) { final FragmentEntity parentFragment = toFragmentEntity(dataspaceEntity, anchorEntity, dataNodeToBeConverted); final Builder<FragmentEntity> childFragmentsImmutableSetBuilder = ImmutableSet.builder(); for (final DataNode childDataNode : dataNodeToBeConverted.getChildDataNodes()) { @@ -226,7 +226,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName); if (isRootXpath(xpath)) { - return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity); + return fragmentRepository.findFirstRootByDataspaceAndAnchor( + dataspaceEntity, anchorEntity); } else { final String normalizedXpath; try { @@ -235,7 +236,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService throw new CpsPathException(e.getMessage()); } - return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, normalizedXpath); + return fragmentRepository.getByDataspaceAndAnchorAndXpath( + dataspaceEntity, anchorEntity, normalizedXpath); } } @@ -319,10 +321,10 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService private List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity, final FetchDescendantsOption fetchDescendantsOption) { - if (fetchDescendantsOption == INCLUDE_ALL_DESCENDANTS) { + if (fetchDescendantsOption.hasNext()) { return fragmentEntity.getChildFragments().stream() - .map(childFragmentEntity -> toDataNode(childFragmentEntity, fetchDescendantsOption)) - .collect(Collectors.toUnmodifiableList()); + .map(childFragmentEntity -> toDataNode(childFragmentEntity, fetchDescendantsOption.next())) + .collect(Collectors.toList()); } return Collections.emptyList(); } @@ -355,10 +357,11 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService final List<DataNode> dataNodes) { final Map<DataNode, FragmentEntity> dataNodeFragmentEntityMap = dataNodes.stream() - .collect(Collectors.toMap( - dataNode -> dataNode, dataNode -> getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath()))); + .collect(Collectors.toMap( + dataNode -> dataNode, + dataNode -> getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath()))); dataNodeFragmentEntityMap.forEach( - (dataNode, fragmentEntity) -> updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode)); + (dataNode, fragmentEntity) -> updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode)); try { fragmentRepository.saveAll(dataNodeFragmentEntityMap.values()); } catch (final StaleStateException staleStateException) { @@ -367,7 +370,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } private void retryUpdateDataNodesIndividually(final String dataspaceName, final String anchorName, - final Collection<FragmentEntity> fragmentEntities) { + final Collection<FragmentEntity> fragmentEntities) { final Collection<String> failedXpaths = new HashSet<>(); fragmentEntities.forEach(dataNodeFragment -> { |