You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2025/12/17 09:50:24 UTC

(jackrabbit-filevault) branch JCRVLT-831 created (now 4e8b1b36)

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

reschke pushed a change to branch JCRVLT-831
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git


      at 4e8b1b36 JCRVLT-831: For collection of namespace prefixed, avoid interating over sibling nodes not contained in the filter(s)

This branch includes the following new commits:

     new 4e8b1b36 JCRVLT-831: For collection of namespace prefixed, avoid interating over sibling nodes not contained in the filter(s)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(jackrabbit-filevault) 01/01: JCRVLT-831: For collection of namespace prefixed, avoid interating over sibling nodes not contained in the filter(s)

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch JCRVLT-831
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit 4e8b1b369bd712ed42efb315bab76175b2bc9e1c
Author: Julian Reschke <re...@apache.org>
AuthorDate: Wed Dec 17 10:49:58 2025 +0100

    JCRVLT-831: For collection of namespace prefixed, avoid interating over sibling nodes not contained in the filter(s)
---
 .../jackrabbit/vault/fs/impl/AggregateImpl.java    | 76 ++++++----------------
 1 file changed, 21 insertions(+), 55 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java
index 189f614d..84782262 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java
@@ -102,7 +102,7 @@ public class AggregateImpl implements Aggregate {
 
     private List<AggregateImpl> leaves;
 
-    private String[] namespacePrefixes;
+    private Set<String> namespacePrefixes = new HashSet<>();
 
     private char state = STATE_INITIAL;
 
@@ -178,7 +178,7 @@ public class AggregateImpl implements Aggregate {
         includes = null;
         binaries = null;
         leaves = null;
-        namespacePrefixes = null;
+        namespacePrefixes = new HashSet<>();
         nodeRef = null;
         relPath = null;
         state = STATE_INITIAL;
@@ -402,10 +402,7 @@ public class AggregateImpl implements Aggregate {
     }
 
     public String[] getNamespacePrefixes() {
-        if (namespacePrefixes == null) {
-            loadNamespaces();
-        }
-        return namespacePrefixes;
+        return namespacePrefixes.toArray(new String[namespacePrefixes.size()]);
     }
 
     public String getNamespaceURI(String prefix) throws RepositoryException {
@@ -455,6 +452,7 @@ public class AggregateImpl implements Aggregate {
             Iterable<Property> properties = new PropertyIterable(node.getProperties());
             for (Property prop : properties) {
                 if (includes(relativePath + "/" + prop.getName())) {
+                    addNamespaceForProperty(prop);
                     aggregateWalkListener.onProperty(prop, depth + 1);
                 }
             }
@@ -535,28 +533,28 @@ public class AggregateImpl implements Aggregate {
         }
     }
 
-    private void addNamespace(Set<String> prefixes, Property prop) throws RepositoryException {
+    private void addNamespaceForProperty(Property prop) throws RepositoryException {
         String propName = prop.getName();
-        addNamespace(prefixes, propName);
+        addNamespaceForName(propName);
         switch (prop.getType()) {
             case PropertyType.NAME:
                 if ("jcr:mixinTypes".equals(propName) || prop.getDefinition().isMultiple()) {
                     Value[] values = prop.getValues();
                     for (Value value: values) {
-                        addNamespace(prefixes, value.getString());
+                        addNamespaceForName(value.getString());
                     }
                 } else {
-                    addNamespace(prefixes, prop.getValue().getString());
+                    addNamespaceForName(prop.getValue().getString());
                 }
                 break;
             case PropertyType.PATH:
                 if (prop.getDefinition().isMultiple()) {
                     Value[] values = prop.getValues();
                     for (Value value: values) {
-                        addNamespacePath(prefixes, value.getString());
+                        addNamespacesForPath(value.getString());
                     }
                 } else {
-                    addNamespacePath(prefixes, prop.getValue().getString());
+                    addNamespacesForPath(prop.getValue().getString());
                 }
                 break;
         }
@@ -601,58 +599,20 @@ public class AggregateImpl implements Aggregate {
         }
     }
 
-    private void addNamespace(Set<String> prefixes, String name) throws RepositoryException {
+    private void addNamespaceForName(String name) {
         int idx = name.indexOf(':');
         if (idx > 0) {
             String pfx = name.substring(0, idx);
-            if (!prefixes.contains(pfx)) {
-                prefixes.add(pfx);
+            if (!namespacePrefixes.contains(pfx)) {
+                namespacePrefixes.add(pfx);
             }
         }
     }
 
-    private void addNamespacePath(Set<String> prefixes, String path) throws RepositoryException {
+    private void addNamespacesForPath(String path) {
         String[] names = path.split("/");
         for (String name: names) {
-            addNamespace(prefixes, name);
-        }
-    }
-
-    private void loadNamespaces() {
-        if (namespacePrefixes == null) {
-            if (log.isDebugEnabled()) {
-                log.trace("loading namespaces of aggregate {}", path);
-            }
-            try {
-                load();
-                Set<String> prefixes = new HashSet<String>();
-                // need to traverse the nodes to get all namespaces
-                loadNamespaces(prefixes, "", getNode());
-                namespacePrefixes = prefixes.toArray(new String[prefixes.size()]);
-            } catch (RepositoryException e) {
-                throw new IllegalStateException("Internal error while loading namespaces", e);
-            }
-        }
-    }
-
-    private void loadNamespaces(Set<String> prefixes, String parentPath, Node node) throws RepositoryException {
-        String name = node.getName();
-        addNamespace(prefixes, name);
-        for (PropertyIterator iter = node.getProperties(); iter.hasNext();) {
-            Property p = iter.nextProperty();
-            String relPath = parentPath + "/" + p.getName();
-            if (includes(relPath)) {
-                addNamespace(prefixes, p);
-            }
-        }
-        for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
-            Node c = iter.nextNode();
-            String relPath = parentPath + "/" + c.getName();
-            if (includes(relPath)) {
-                loadNamespaces(prefixes, relPath, c);
-            } else if (node.getPrimaryNodeType().hasOrderableChildNodes()) {
-                addNamespace(prefixes, c.getName());
-            }
+            addNamespaceForName(name);
         }
     }
 
@@ -714,12 +674,16 @@ public class AggregateImpl implements Aggregate {
         // get a node iterator suitable for the current node and the applicable filters
         NodeIterator nIter = getNodeIteratorFor(node, filter);
 
+        int visited = 0;
+
         // include "our" nodes to the include set and delegate the others to the
         // respective aggregator building sub aggregates
         while (nIter.hasNext()) {
             Node n = nIter.nextNode();
+            visited += 1;
             String path = n.getPath();
             log.trace("checking {}", path);
+            addNamespacesForPath(path);
 
             PathFilterSet coverSet = filter.getCoveringFilterSet(path);
             boolean isAncestor = filter.isAncestor(path);
@@ -777,6 +741,8 @@ public class AggregateImpl implements Aggregate {
                 }
             }
         }
+
+        log.debug("In " + node.getPath() + ", visited " + visited + " siblings");
     }
 
     private static NodeIterator getNodeIteratorFor(Node node, WorkspaceFilter filter) throws RepositoryException {