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/03/13 10:48:20 UTC
(jackrabbit-filevault) 02/02: JCRVLT-789: AggregateImpl might be able to avoid iterating over sibling nodes - fix javadoc and handle 'unrelated' filter root case
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch JCRVLT-789
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
commit 1cf88160a6b0d03704c85b0d6f07085c14cf8137
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Mar 13 11:48:07 2025 +0100
JCRVLT-789: AggregateImpl might be able to avoid iterating over sibling nodes - fix javadoc and handle 'unrelated' filter root case
---
.../packaging/integration/SiblingIterationIT.java | 5 ++---
.../apache/jackrabbit/vault/fs/api/FilterSet.java | 21 ++++++++++++++++-----
.../jackrabbit/vault/fs/api/WorkspaceFilter.java | 3 ++-
.../vault/fs/config/DefaultWorkspaceFilter.java | 3 ++-
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/packaging/integration/SiblingIterationIT.java b/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/packaging/integration/SiblingIterationIT.java
index d7ce741a..6182cdc1 100644
--- a/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/packaging/integration/SiblingIterationIT.java
+++ b/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/packaging/integration/SiblingIterationIT.java
@@ -84,13 +84,12 @@ public class SiblingIterationIT extends IntegrationTestBase {
@Test
// two filters, root below test resource, one unrelated
- public void testOneMatchingOneNonMatchFilter() throws RepositoryException, IOException {
+ public void testOneMatchingOneNonMatchingFilter() throws RepositoryException, IOException {
DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
filter.add(new PathFilterSet("/" + ROOT + "/" + DO_FIND_ME));
filter.add(new PathFilterSet("/" + ROOT + "xyz"));
- // TODO, for now confirm sub-optimal behaviour
- internalTestSiblingIteration(filter, true);
+ internalTestSiblingIteration(filter, false);
}
private void internalTestSiblingIteration(WorkspaceFilter filter, boolean expectIterated) throws RepositoryException, IOException {
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
index 0ca382e5..b2a507f9 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
@@ -232,7 +232,7 @@ public abstract class FilterSet<E extends Filter> implements Dumpable {
}
/**
- * Checks if the given item is covered by this filter set. I.e. if the node
+ * Checks if the given path is covered by this filter set. I.e. if the node
* addressed by the {@code root} path is an ancestor of the given item.
*
* @param path path of the item
@@ -243,7 +243,7 @@ public abstract class FilterSet<E extends Filter> implements Dumpable {
}
/**
- * Checks if the given item is an ancestor of the filter's root path.
+ * Checks if the given path is an ancestor of the filter's root path.
* @param path path of the item to check
* @return {@code true} if the given item is an ancestor
*/
@@ -255,7 +255,8 @@ public abstract class FilterSet<E extends Filter> implements Dumpable {
/**
* Matches the given path with this filter's root. If it is an ancestor, returns the name of the first
- * path segment of the remaining filter root "below" path.
+ * path segment of the remaining filter root "below" path. If it's unrelated, return an empty string
+ * (indicating that no child node will ever math). Otherwise return {@code null).}
*
* @param path Path to check
* @return first path segment of non-matched path, or {@code null} when path not ancestor
@@ -267,7 +268,7 @@ public abstract class FilterSet<E extends Filter> implements Dumpable {
String pathMatch = appendSlashIfNeeded(path);
if (rootMatch.equals(pathMatch)) {
- // examples:
+ // examples
// path "/x/y", root "/x/y" -> "" -> null
result = null;
@@ -286,8 +287,18 @@ public abstract class FilterSet<E extends Filter> implements Dumpable {
}
result = rel;
+ } else if (pathMatch.startsWith(rootMatch)) {
+ // examples
+ // path "/x/y/z", root "/x/y" -> null
+
+ return null;
+ } else if (!pathMatch.startsWith(rootMatch) && !rootMatch.startsWith(pathMatch)) {
+ // unrelated paths, example:
+ // path "/x/y/z", root "/a/b" -> ""
+ result = "";
} else {
- // otherwise
+ // otherwise, should really not get here
+ log.error("should not get here: getDirectChildNameTowardsFilterRoot(root={}, path={}) -> null", rootMatch, pathMatch);
result = null;
}
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java
index c9697077..5ac58727 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java
@@ -104,7 +104,8 @@ public interface WorkspaceFilter extends Dumpable {
boolean isAncestor(@NotNull String path);
/**
- * Matches the given path with all filter roots. For each, if it is an ancestor,
+ * Matches the given path with all filter roots. For each, if it is an ancestor
+ * <em>or</em> if it is unrelated to the path (neither ancestor, self or descendant),
* add the name of the first path segment of the remaining filter root "below" path
* to the result set.
* <p>
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
index 1549d907..4cda709f 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
@@ -300,8 +300,9 @@ public class DefaultWorkspaceFilter implements Dumpable, WorkspaceFilter {
if (childName == null) {
// we don't know, so we can't compute the set (early exit)
return null;
+ } else if (!childName.isEmpty()) {
+ result.add(childName);
}
- result.add(childName);
}
return result;
}