Move predicate matching to MatchCache
Clarify the intents of PredicateCache and MatchCache by only doing
matching in MatchCache. This reduces some of the double accounting on
match statistics and makes it easier to understand the matching
exceptions.
Change-Id: I9157b15851c2bf4d1938dab11a9ae45495468f55
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java b/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java
index ab51a55..55cae12 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java
@@ -38,12 +38,12 @@
public boolean match(ChangeData changeData, String query)
throws StorageException, QueryParseException {
- if (query == null) {
+ if (query == null || "true".equalsIgnoreCase(query)) {
return true;
}
Boolean isMatched = resultByChangeByQuery.get(query, changeData.getId());
if (isMatched == null) {
- isMatched = predicateCache.matchWithExceptions(changeData, query);
+ isMatched = predicateCache.getPredicate(query).asMatchable().match(changeData);
resultByChangeByQuery.put(query, changeData.getId(), isMatched);
}
return isMatched;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java b/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java
index 23644d1..53e2ac8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java
@@ -14,7 +14,6 @@
package com.googlesource.gerrit.plugins.task;
-import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.index.FieldDef;
import com.google.gerrit.index.query.AndPredicate;
@@ -40,7 +39,6 @@
public class PredicateCache {
public static class Statistics {
protected Object predicatesByQueryCache;
- protected long numberOfMatches;
}
protected final ChangeQueryBuilder cqb;
@@ -77,18 +75,7 @@
return statistics;
}
- public boolean matchWithExceptions(ChangeData c, String query)
- throws QueryParseException, StorageException {
- if ("true".equalsIgnoreCase(query)) {
- return true;
- }
- if (statistics != null) {
- statistics.numberOfMatches++;
- }
- return getPredicate(query).asMatchable().match(c);
- }
-
- protected Predicate<ChangeData> getPredicate(String query) throws QueryParseException {
+ public Predicate<ChangeData> getPredicate(String query) throws QueryParseException {
ThrowingProvider<Predicate<ChangeData>, QueryParseException> predProvider =
predicatesByQuery.getOrStartLoad(query);
if (predProvider != null) {