joerghoh commented on code in PR #175:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/175#discussion_r2087232495


##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java:
##########
@@ -300,40 +308,80 @@ private boolean doUpdateAliasInMap(final Resource 
resource) {
             if 
(containingResource.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) 
{
                 changed |= doAddAlias(containingResource);
             }
-            final Resource child = containingResource.getChild(JCR_CONTENT);
+            Resource child = containingResource.getChild(JCR_CONTENT);
             if (child != null && 
child.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) {
                 changed |= doAddAlias(child);
             }
 
             return changed;
         } else {
             log.warn("containingResource is null for alias on {}, skipping.", 
resource.getPath());
+            return false;
         }
+    }
 
-        return false;
+    public @NotNull Map<String, Collection<String>> getAliasMap(@Nullable 
String parentPath) {
+        Map<String, Collection<String>> result = this.aliasMapsMap != 
UNITIALIZED_MAP
+                ? getAliasMapFromCache(parentPath)
+                : getAliasMapFromRepo(parentPath);
+        return result != null ? result : Collections.emptyMap();
     }
 
-    public @NotNull Map<String, Collection<String>> getAliasMap(final String 
parentPath) {
-        Map<String, Collection<String>> aliasMapForParent = 
aliasMapsMap.get(parentPath);
-        return aliasMapForParent != null ? aliasMapForParent : 
Collections.emptyMap();
+    private @Nullable Map<String, Collection<String>> 
getAliasMapFromCache(@Nullable String parentPath) {
+        return aliasMapsMap.get(parentPath);
+    }
+
+    // TODO: there's an opportunity for optimization when the caller already 
has a Resource
+    private @Nullable Map<String, Collection<String>> 
getAliasMapFromRepo(@Nullable String parentPath) {
+
+        if (parentPath == null) {
+            return null;
+        } else {
+            try (ResourceResolver resolver =
+                    
factory.getServiceResourceResolver(factory.getServiceUserAuthenticationInfo(SERVICE_USER)))
 {
+
+                Resource parent = resolver.getResource(parentPath);
+                return getAliasMapFromRepo(parent);
+            } catch (LoginException ex) {
+                log.error("Could not obtain resolver", ex);

Review Comment:
   I would make this log message a bit more helpful
   ```suggestion
                   log.error("Could not obtain resolver to resolve any aliases 
from repository", ex);
   ```



-- 
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

Reply via email to