joerghoh commented on code in PR #177: URL: https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/177#discussion_r2095439215
########## src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java: ########## @@ -927,55 +927,26 @@ private Resource getChildInternal(final Resource parent, final String childName) // we do not have a child with the exact name, so we look for // a child, whose alias matches the childName - if (factory.getMapEntries().isOptimizeAliasResolutionEnabled()) { - final String parentPath = parent.getPath(); - logger.debug( - "getChildInternal: Optimize Alias Resolution is Enabled, looking up {} in {}", - childName, - parentPath); - - // optimized alias resolution: aliases are cached by MapEntries - final Optional<String> aliasedResourceName = - factory.getMapEntries().getAliasMap(parentPath).entrySet().stream() - .filter(e -> e.getValue().contains(childName)) - .findFirst() - .map(Map.Entry::getKey); - if (aliasedResourceName.isPresent()) { - // we know that MapEntries already has checked for valid aliases - final String aliasPath = parentPath + '/' + aliasedResourceName.get(); - final Resource aliasedChild = - getAbsoluteResourceInternal(parent, ResourceUtil.normalize(aliasPath), EMPTY_PARAMETERS, true); - logger.debug("getChildInternal: Found Resource {} with alias {} to use", aliasedChild, childName); - return aliasedChild; - } + final String parentPath = parent.getPath(); + logger.debug("getChildInternal: looking up {} in {}", childName, parentPath); + + final Optional<String> aliasedResourceName = factory.getMapEntries().getAliasMap(parent).entrySet().stream() + .filter(e -> e.getValue().contains(childName)) + .findFirst() + .map(Map.Entry::getKey); + + if (aliasedResourceName.isPresent()) { + // we know that MapEntries already has checked for valid aliases + final String aliasPath = parentPath + '/' + aliasedResourceName.get(); + final Resource aliasedChild = + getAbsoluteResourceInternal(parent, ResourceUtil.normalize(aliasPath), EMPTY_PARAMETERS, true); + logger.debug("getChildInternal: Found Resource {} with alias {} to use", aliasedChild, childName); + return aliasedChild; } else { - if (this.factory.isOptimizeAliasResolutionEnabled()) { - this.factory.getMapEntries().logDisableAliasOptimization(); - } - logger.debug("getChildInternal: Optimize Alias Resolution is Disabled"); - final Iterator<Resource> children = listChildren(parent); - while (children.hasNext()) { - child = children.next(); - if (!child.getPath().endsWith(JCR_CONTENT_LEAF)) { - final String[] aliases = ResourceResolverControl.getProperty(child, PROP_ALIAS, String[].class); - if (aliases != null) { - for (final String alias : aliases) { - if (childName.equals(alias)) { - logger.debug( - "getChildInternal: Found Resource {} with alias {} to use", child, childName); - final Resource aliasedChild = getAbsoluteResourceInternal( - parent, ResourceUtil.normalize(child.getPath()), EMPTY_PARAMETERS, true); - return aliasedChild; - } - } - } - } - } + // no match for the childName found + logger.debug("getChildInternal: Resource {} has no child {}", parent, childName); + return null; Review Comment: Nit: I would have left this as is and would have remove the entire ``else`` branch instead; the diff would have been a bit smaller. ########## src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java: ########## @@ -930,7 +930,7 @@ private Resource getChildInternal(final Resource parent, final String childName) final String parentPath = parent.getPath(); logger.debug("getChildInternal: looking up {} in {}", childName, parentPath); - final Optional<String> aliasedResourceName = factory.getMapEntries().getAliasMap(parentPath).entrySet().stream() + final Optional<String> aliasedResourceName = factory.getMapEntries().getAliasMap(parent).entrySet().stream() Review Comment: Nit: when you don't need the ``parentPath`` here but only in the branch below (line 938ff), I would also move its declaration down there. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@sling.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org