You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/05/14 10:00:27 UTC

(sling-org-apache-sling-resourceresolver) 01/01: SLING-12759: ResourceResolver: push 'non-optimized' alias handling from ResourceResolverImpl into AliasHandler

This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch SLING-12759b
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 8b5c5b49b1454959baeb0a2fc4d96e0c319bb21d
Author: Julian Reschke <re...@apache.org>
AuthorDate: Wed May 14 11:00:10 2025 +0100

    SLING-12759: ResourceResolver: push 'non-optimized' alias handling from ResourceResolverImpl into AliasHandler
---
 .../impl/ResourceResolverImpl.java                 | 65 ++++++----------------
 1 file changed, 18 insertions(+), 47 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
index a123f83c..d0c25541 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
@@ -927,55 +927,26 @@ public class ResourceResolverImpl extends SlingAdaptable implements ResourceReso
 
         // 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(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;
         } 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;
         }
-
-        // no match for the childName found
-        logger.debug("getChildInternal: Resource {} has no child {}", parent, childName);
-        return null;
     }
 
     /**