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/04/29 16:08:38 UTC

(sling-org-apache-sling-resourceresolver) branch SLING-12769 updated: SLING-12769: alias refactoring - MapEntries - push alias updated logic into AliasHandler

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

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


The following commit(s) were added to refs/heads/SLING-12769 by this push:
     new 2afec545 SLING-12769: alias refactoring - MapEntries - push alias updated logic into AliasHandler
2afec545 is described below

commit 2afec545e948a63c522b9adb42e87a2ef2ce6421
Author: Julian Reschke <re...@apache.org>
AuthorDate: Tue Apr 29 17:08:29 2025 +0100

    SLING-12769: alias refactoring - MapEntries - push alias updated logic into AliasHandler
---
 .../impl/mapping/AliasHandler.java                 |  8 +++
 .../resourceresolver/impl/mapping/MapEntries.java  | 57 +++++++++++-----------
 2 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
index e6e3faa3..40e104f3 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
@@ -257,6 +257,14 @@ class AliasHandler {
      * @return {@code true} if any change
      */
     boolean doUpdateAlias(final Resource resource) {
+        if (!cacheIsInitialized) {
+            return false;
+        } else {
+            return doUpdateAliasInMap(resource);
+        }
+    }
+
+    private boolean doUpdateAliasInMap(final Resource resource) {
 
         // resource containing the alias
         final Resource containingResource = getResourceToBeAliased(resource);
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
index 1fe1c29d..fa481b7c 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
@@ -187,38 +187,39 @@ public class MapEntries implements MapEntriesHandler, ResourceChangeListener, Ex
     }
 
     private boolean updateResource(final String path, final AtomicBoolean resolverRefreshed) {
-        final boolean isValidVanityPath = vph.isValidVanityPath(path);
-        if (this.ah.usesCache() || isValidVanityPath) {
-            this.initializing.lock();
 
-            try {
-                this.refreshResolverIfNecessary(resolverRefreshed);
-                final Resource resource = this.resolver != null ? resolver.getResource(path) : null;
-                if (resource != null) {
-                    boolean vanityPathChanged = false;
-                    boolean aliasChanged = false;
-
-                    if (isValidVanityPath) {
-                        // we remove the old vanity path first
-                        vanityPathChanged |= vph.doRemoveVanity(path);
-
-                        // add back vanity path
-                        Resource contentRsrc = null;
-                        if (!resource.getName().equals(JCR_CONTENT)) {
-                            // there might be a JCR_CONTENT child resource
-                            contentRsrc = resource.getChild(JCR_CONTENT);
-                        }
-                        vanityPathChanged |= vph.doAddVanity(contentRsrc != null ? contentRsrc : resource);
-                    }
-                    if (this.ah.usesCache()) {
-                        aliasChanged |= ah.doUpdateAlias(resource);
-                    }
+        this.initializing.lock();
+
+        try {
+            this.refreshResolverIfNecessary(resolverRefreshed);
+
+            final Resource resource = this.resolver != null ? resolver.getResource(path) : null;
+
+            final boolean isValidVanityPath = vph.isValidVanityPath(path);
 
-                    return vanityPathChanged || aliasChanged;
+            if (resource != null) {
+
+                boolean vanityPathChanged = false;
+                boolean aliasChanged = false;
+
+                if (isValidVanityPath) {
+                    // we remove the old vanity path first
+                    vanityPathChanged |= vph.doRemoveVanity(path);
+
+                    // add back vanity path
+                    Resource contentRsrc = null;
+                    if (!resource.getName().equals(JCR_CONTENT)) {
+                        // there might be a JCR_CONTENT child resource
+                        contentRsrc = resource.getChild(JCR_CONTENT);
+                    }
+                    vanityPathChanged |= vph.doAddVanity(contentRsrc != null ? contentRsrc : resource);
                 }
-            } finally {
-                this.initializing.unlock();
+
+                aliasChanged |= ah.doUpdateAlias(resource);
+                return vanityPathChanged || aliasChanged;
             }
+        } finally {
+            this.initializing.unlock();
         }
 
         return false;