Delete ChangeOperatorPredicate and use PostFilterPredicate instead

Using PostFilterPredicate better describes what these predicates do,
they post filter the result of change queries. With this change the
behaviour doesn’t change, especially for queries with a post filter
predicate but no index predicate we still fall back to query only open
changes. This should be addressed in a follow-up change.

Change-Id: I6527e15777c174e7616a56a82fdd1c69ad98f9c5
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2018-04-18 09:03:16 +02:00
parent bb51f1b27a
commit 393e008070
8 changed files with 20 additions and 64 deletions

View File

@ -18,4 +18,8 @@ package com.google.gerrit.index.query;
* Matches all documents in the index, with additional filtering done in the subclass's {@code
* match} method.
*/
public abstract class PostFilterPredicate<T> extends Predicate<T> implements Matchable<T> {}
public abstract class PostFilterPredicate<T> extends OperatorPredicate<T> implements Matchable<T> {
public PostFilterPredicate(String operator, String value) {
super(operator, value);
}
}

View File

@ -49,6 +49,7 @@ public class AccountQueryBuilder extends QueryBuilder<AccountState> {
private static final Logger log = LoggerFactory.getLogger(AccountQueryBuilder.class);
public static final String FIELD_ACCOUNT = "account";
public static final String FIELD_CAN_SEE = "cansee";
public static final String FIELD_EMAIL = "email";
public static final String FIELD_LIMIT = "limit";
public static final String FIELD_NAME = "name";

View File

@ -15,7 +15,6 @@
package com.google.gerrit.server.query.account;
import com.google.gerrit.index.query.PostFilterPredicate;
import com.google.gerrit.index.query.Predicate;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.notedb.ChangeNotes;
@ -24,8 +23,6 @@ import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;
import java.util.Collection;
import java.util.Objects;
public class CanSeeChangePredicate extends PostFilterPredicate<AccountState> {
private final Provider<ReviewDb> db;
@ -34,6 +31,7 @@ public class CanSeeChangePredicate extends PostFilterPredicate<AccountState> {
CanSeeChangePredicate(
Provider<ReviewDb> db, PermissionBackend permissionBackend, ChangeNotes changeNotes) {
super(AccountQueryBuilder.FIELD_CAN_SEE, changeNotes.getChangeId().toString());
this.db = db;
this.permissionBackend = permissionBackend;
this.changeNotes = changeNotes;
@ -56,24 +54,4 @@ public class CanSeeChangePredicate extends PostFilterPredicate<AccountState> {
public int getCost() {
return 1;
}
@Override
public Predicate<AccountState> copy(Collection<? extends Predicate<AccountState>> children) {
return new CanSeeChangePredicate(db, permissionBackend, changeNotes);
}
@Override
public int hashCode() {
return Objects.hash(changeNotes.getChange().getChangeId());
}
@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}
return getClass() == other.getClass()
&& changeNotes.getChange().getChangeId()
== ((CanSeeChangePredicate) other).changeNotes.getChange().getChangeId();
}
}

View File

@ -1,26 +0,0 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.index.query.Matchable;
import com.google.gerrit.index.query.OperatorPredicate;
public abstract class ChangeOperatorPredicate extends OperatorPredicate<ChangeData>
implements Matchable<ChangeData> {
protected ChangeOperatorPredicate(String name, String value) {
super(name, value);
}
}

View File

@ -15,6 +15,7 @@
package com.google.gerrit.server.query.change;
import com.google.gerrit.common.data.SubmitTypeRecord;
import com.google.gerrit.index.query.PostFilterPredicate;
import com.google.gerrit.index.query.Predicate;
import com.google.gerrit.index.query.QueryParseException;
import com.google.gerrit.reviewdb.client.BooleanProjectConfig;
@ -77,18 +78,17 @@ public class ConflictsPredicate {
and.add(Predicate.or(filePredicates));
ChangeDataCache changeDataCache = new ChangeDataCache(cd, args.projectCache);
and.add(new CheckConflict(ChangeQueryBuilder.FIELD_CONFLICTS, value, args, c, changeDataCache));
and.add(new CheckConflict(value, args, c, changeDataCache));
return Predicate.and(and);
}
private static final class CheckConflict extends ChangeOperatorPredicate {
private static final class CheckConflict extends PostFilterPredicate<ChangeData> {
private final Arguments args;
private final Branch.NameKey dest;
private final ChangeDataCache changeDataCache;
CheckConflict(
String field, String value, Arguments args, Change c, ChangeDataCache changeDataCache) {
super(field, value);
CheckConflict(String value, Arguments args, Change c, ChangeDataCache changeDataCache) {
super(ChangeQueryBuilder.FIELD_CONFLICTS, value);
this.args = args;
this.dest = c.getDest();
this.changeDataCache = changeDataCache;

View File

@ -14,12 +14,13 @@
package com.google.gerrit.server.query.change;
import com.google.gerrit.index.query.PostFilterPredicate;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
import java.util.Set;
public class DestinationPredicate extends ChangeOperatorPredicate {
public class DestinationPredicate extends PostFilterPredicate<ChangeData> {
protected Set<Branch.NameKey> destinations;
public DestinationPredicate(Set<Branch.NameKey> destinations, String value) {

View File

@ -14,25 +14,22 @@
package com.google.gerrit.server.query.change;
import com.google.gerrit.index.query.PostFilterPredicate;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gwtorm.server.OrmException;
public class OwnerinPredicate extends ChangeOperatorPredicate {
public class OwnerinPredicate extends PostFilterPredicate<ChangeData> {
protected final IdentifiedUser.GenericFactory userFactory;
protected final AccountGroup.UUID uuid;
public OwnerinPredicate(IdentifiedUser.GenericFactory userFactory, AccountGroup.UUID uuid) {
super(ChangeQueryBuilder.FIELD_OWNERIN, uuid.toString());
super(ChangeQueryBuilder.FIELD_OWNERIN, uuid.get());
this.userFactory = userFactory;
this.uuid = uuid;
}
protected AccountGroup.UUID getAccountGroupUUID() {
return uuid;
}
@Override
public boolean match(ChangeData object) throws OrmException {
final Change change = object.change();

View File

@ -14,17 +14,18 @@
package com.google.gerrit.server.query.change;
import com.google.gerrit.index.query.PostFilterPredicate;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gwtorm.server.OrmException;
public class ReviewerinPredicate extends ChangeOperatorPredicate {
public class ReviewerinPredicate extends PostFilterPredicate<ChangeData> {
protected final IdentifiedUser.GenericFactory userFactory;
protected final AccountGroup.UUID uuid;
public ReviewerinPredicate(IdentifiedUser.GenericFactory userFactory, AccountGroup.UUID uuid) {
super(ChangeQueryBuilder.FIELD_REVIEWERIN, uuid.toString());
super(ChangeQueryBuilder.FIELD_REVIEWERIN, uuid.get());
this.userFactory = userFactory;
this.uuid = uuid;
}