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/01/14 17:29:46 UTC

(sling-org-apache-sling-resourceresolver) 02/02: Resource Resolver: refactor MapEntries - extract vanity path handling - remove use of instance variable to decide whether to count

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

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

commit 8a846c6f2213cf29a7b98d73215619e1ee08e7f3
Author: Julian Reschke <re...@apache.org>
AuthorDate: Tue Jan 14 18:29:35 2025 +0100

    Resource Resolver: refactor MapEntries - extract vanity path handling - remove use of instance variable to decide whether to count
---
 .../sling/resourceresolver/impl/mapping/MapEntries.java    | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

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 7d6d7e4..116441b 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
@@ -560,7 +560,7 @@ public class MapEntries implements
         log.debug("doAddVanity getting {}", resource.getPath());
 
         boolean updateTheCache = isAllVanityPathEntriesCached() || vanityPathHandler.getCounter().get() < this.factory.getMaxCachedVanityPathEntries();
-        return null != loadVanityPath(resource, resolveMapsMap, vanityTargets, updateTheCache);
+        return null != loadVanityPath(resource, resolveMapsMap, vanityTargets, updateTheCache, true);
     }
 
     private boolean doRemoveVanity(final String path) {
@@ -975,11 +975,11 @@ public class MapEntries implements
                 if ( isValid ) {
                     totalValid += 1;
                     if (this.vanityPathsProcessed.get() && (this.factory.isMaxCachedVanityPathEntriesStartup() || vanityPathHandler.getCounter().get() < this.factory.getMaxCachedVanityPathEntries())) {
-                        loadVanityPath(resource, resolveMapsMap, vanityTargets, true);
+                        loadVanityPath(resource, resolveMapsMap, vanityTargets, true, true);
                         entryMap = resolveMapsMap;
                     } else {
                         final Map <String, List<String>> targetPaths = new HashMap<>();
-                        loadVanityPath(resource, entryMap, targetPaths, true);
+                        loadVanityPath(resource, entryMap, targetPaths, true, false);
                     }
                 }
             }
@@ -1317,7 +1317,7 @@ public class MapEntries implements
                 countInScope += 1;
                 final boolean addToCache = isAllVanityPathEntriesCached()
                         || vanityPathHandler.getCounter().get() < this.factory.getMaxCachedVanityPathEntries();
-                loadVanityPath(resource, resolveMapsMap, targetPaths, addToCache);
+                loadVanityPath(resource, resolveMapsMap, targetPaths, addToCache, true);
             }
         }
         long processElapsed = System.nanoTime() - processStart;
@@ -1340,7 +1340,9 @@ public class MapEntries implements
      * 
      * @return first vanity path or {@code null}
      */
-    private String loadVanityPath(final Resource resource, final Map<String, List<MapEntry>> entryMap, final Map <String, List<String>> targetPaths, boolean addToCache) {
+    private String loadVanityPath(final Resource resource, final Map<String, List<MapEntry>> entryMap,
+                                  final Map <String, List<String>> targetPaths,
+                                  boolean addToCache, boolean updateCounter) {
 
         if (!this.vanityPathHandler.isValidVanityPath(resource.getPath())) {
             return null;
@@ -1406,7 +1408,7 @@ public class MapEntries implements
                         // 3. keep the path to return
                         this.vanityPathHandler.updateTargetPaths(targetPaths, redirect, checkPath);
                         //increment only if the instance variable
-                        if (entryMap == resolveMapsMap) {
+                        if (updateCounter) {
                             this.vanityPathHandler.getCounter().getAndAdd(2);
                         }