You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2021/01/08 10:29:26 UTC

[GitHub] [sling-org-apache-sling-resourceresolver] akankshajain18 commented on a change in pull request #24: SLING-9535 - Improve performance of sling:alias

akankshajain18 commented on a change in pull request #24:
URL: https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/24#discussion_r553864141



##########
File path: src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
##########
@@ -1038,22 +1016,69 @@ private boolean addEntry(final Map<String, List<MapEntry>> entryMap, final Strin
      */
     private Map<String, Map<String, String>> loadAliases(final ResourceResolver resolver) {
         final Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
-        final String queryString = ALIAS_QUERY_DEFAULT;
-		        final Iterator<Resource> i = resolver.findResources(queryString, "sql");
-		        while (i.hasNext()) {
+        final String queryString = updateAliasQuery();
+        final Iterator<Resource> i = resolver.findResources(queryString, "sql");
+		     while (i.hasNext()) {
 		            final Resource resource = i.next();
 		            loadAlias(resource, map);
 		        }
         return map;
     }
 
-	/**
+
+    /*
+    * Update alias query based on configured alias locations
+    */
+    private String updateAliasQuery(){
+        final Set<String> allowedLocations = this.factory.getAllowedAliasLocations();
+
+        StringBuilder baseQuery = new StringBuilder(ALIAS_BASE_QUERY_DEFAULT);
+        baseQuery.append(" ").append("WHERE");
+
+        if(allowedLocations.isEmpty()){
+            baseQuery.append(" ").append("(").append("NOT ISDESCENDANTNODE(page,")
+                    .append("\"").append(JCR_SYSTEM_PREFIX).append("\"").append("))");
+
+        }else{
+            Iterator<String> pathIterator = allowedLocations.iterator();
+            baseQuery.append("(");
+            while(pathIterator.hasNext()){
+                String prefix = pathIterator.next();
+                baseQuery.append(" ").append("ISDESCENDANTNODE(page,")
+                        .append("\"").append(prefix).append("\"")
+                        .append(")").append(" ").append("OR");
+            }
+            //Remove last "OR" keyword
+            int orLastIndex = baseQuery.lastIndexOf("OR");
+            baseQuery.delete(orLastIndex,baseQuery.length());
+            baseQuery.append(")");
+        }
+
+        baseQuery.append(" AND sling:alias IS NOT NULL ");
+        String aliasQuery = baseQuery.toString();
+        logger.debug("Query to fetch alias [{}] ", aliasQuery);
+
+        return aliasQuery;
+    }
+
+    /**
+     *
+     *  validate alias path based on configuration provided
+     */
+    protected boolean isValidAliasPath(final String path){

Review comment:
       IF the alias path is null then it throw IllegalArgumentException otherwise it returns true.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org