You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2013/12/19 17:45:02 UTC
svn commit: r1552349 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java
Author: jukka
Date: Thu Dec 19 16:45:01 2013
New Revision: 1552349
URL: http://svn.apache.org/r1552349
Log:
OAK-1273: Reduce overhead when handling many parallel property indices
Only read the jcr:primaryType or jcr:mixinTypes properties if their value could possibly fulfill a type predicate
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java?rev=1552349&r1=1552348&r2=1552349&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java Thu Dec 19 16:45:01 2013
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.plugin
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.in;
-import static com.google.common.collect.Iterables.addAll;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Collections.singleton;
@@ -50,6 +49,8 @@ public class TypePredicate implements Pr
private final Iterable<String> names;
+ private boolean initialized = false;
+
private Set<String> primaryTypes = null;
private Set<String> mixinTypes = null;
@@ -80,18 +81,34 @@ public class TypePredicate implements Pr
this.names = names;
}
+ private static Set<String> add(Set<String> names, String name) {
+ if (names == null) {
+ return newHashSet(name);
+ } else {
+ names.add(name);
+ return names;
+ }
+ }
+
private void addNodeType(NodeState types, String name) {
NodeState type = types.getChildNode(name);
- addAll(primaryTypes, type.getNames(OAK_PRIMARY_SUBTYPES));
+
+ for (String primary : type.getNames(OAK_PRIMARY_SUBTYPES)) {
+ primaryTypes = add(primaryTypes, primary);
+ }
+
if (type.getBoolean(JCR_ISMIXIN)) {
- mixinTypes.add(name);
+ mixinTypes = add(mixinTypes, name);
+
// Only mixin types can have mixin descendants, so we
// only fill the mixinTypes set in this branch of code.
- addAll(mixinTypes, type.getNames(OAK_MIXIN_SUBTYPES));
+ for (String mixin : type.getNames(OAK_MIXIN_SUBTYPES)) {
+ mixinTypes = add(mixinTypes, mixin);
+ }
} else {
// No need to check whether the type actually exists, as if
// it doesn't there should in any case be no matching content.
- primaryTypes.add(name);
+ primaryTypes = add(primaryTypes, name);
}
}
@@ -99,20 +116,26 @@ public class TypePredicate implements Pr
@Override
public boolean apply(NodeState input) {
- if (primaryTypes == null) {
+ if (!initialized) {
// lazy initialization of the sets of matching type names
- primaryTypes = newHashSet();
- mixinTypes = newHashSet();
NodeState types = checkNotNull(root)
.getChildNode(JCR_SYSTEM)
.getChildNode(JCR_NODE_TYPES);
for (String name : checkNotNull(names)) {
addNodeType(types, name);
}
+ initialized = true;
}
- return primaryTypes.contains(input.getName(JCR_PRIMARYTYPE))
- || any(input.getNames(JCR_MIXINTYPES), in(mixinTypes));
+ if (primaryTypes != null
+ && primaryTypes.contains(input.getName(JCR_PRIMARYTYPE))) {
+ return true;
+ } else if (mixinTypes != null
+ && any(input.getNames(JCR_MIXINTYPES), in(mixinTypes))) {
+ return true;
+ } else {
+ return false;
+ }
}
//------------------------------------------------------------< Object >--