Add attention set to index
Change-Id: I22d2aa7b73cbbdf0d24cc4e49a0263705ea0229d
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2020 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 static com.google.gerrit.server.util.AttentionSetUtil.additionsOnly;
|
||||
|
||||
import com.google.gerrit.entities.Account;
|
||||
import com.google.gerrit.server.index.change.ChangeField;
|
||||
|
||||
/** Simple predicate for searching by attention set. */
|
||||
public class AttentionSetPredicate extends ChangeIndexPredicate {
|
||||
protected final Account.Id id;
|
||||
|
||||
AttentionSetPredicate(Account.Id id) {
|
||||
super(ChangeField.ATTENTION_SET_USERS, id.toString());
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(ChangeData changeData) {
|
||||
return additionsOnly(changeData.attentionSet()).stream()
|
||||
.anyMatch(update -> update.account().equals(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -611,6 +611,21 @@ public class ChangeData {
|
||||
return attentionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified attention set. If two or more entries refer to the same user, throws an
|
||||
* {@link IllegalStateException}.
|
||||
*/
|
||||
public void setAttentionSet(ImmutableSet<AttentionSetUpdate> attentionSet) {
|
||||
if (attentionSet.stream().map(AttentionSetUpdate::account).distinct().count()
|
||||
!= attentionSet.size()) {
|
||||
throw new IllegalStateException(
|
||||
String.format(
|
||||
"Stored attention set for change %d contains duplicate update",
|
||||
change.getId().get()));
|
||||
}
|
||||
this.attentionSet = attentionSet;
|
||||
}
|
||||
|
||||
/** @return patches for the change, in patch set ID order. */
|
||||
public Collection<PatchSet> patchSets() {
|
||||
if (patchSets == null) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.query.change;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.gerrit.entities.Change.CHANGE_ID_PATTERN;
|
||||
import static com.google.gerrit.server.account.AccountResolver.isSelf;
|
||||
import static com.google.gerrit.server.query.change.ChangeData.asChanges;
|
||||
@@ -136,6 +137,8 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
|
||||
|
||||
public static final String FIELD_ADDED = "added";
|
||||
public static final String FIELD_AGE = "age";
|
||||
public static final String FIELD_ATTENTION_SET_USERS = "attentionusers";
|
||||
public static final String FIELD_ATTENTION_SET_FULL = "attentionfull";
|
||||
public static final String FIELD_ASSIGNEE = "assignee";
|
||||
public static final String FIELD_AUTHOR = "author";
|
||||
public static final String FIELD_EXACTAUTHOR = "exactauthor";
|
||||
@@ -1056,6 +1059,20 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
|
||||
return owner(accounts);
|
||||
}
|
||||
|
||||
@Operator
|
||||
public Predicate<ChangeData> attention(String who)
|
||||
throws QueryParseException, IOException, ConfigInvalidException {
|
||||
if (!args.index.getSchema().hasField(ChangeField.ATTENTION_SET_USERS)) {
|
||||
throw new QueryParseException(
|
||||
"'attention' operator is not supported by change index version");
|
||||
}
|
||||
return attention(parseAccount(who, (AccountState s) -> true));
|
||||
}
|
||||
|
||||
private Predicate<ChangeData> attention(Set<Account.Id> who) {
|
||||
return Predicate.or(who.stream().map(AttentionSetPredicate::new).collect(toImmutableSet()));
|
||||
}
|
||||
|
||||
@Operator
|
||||
public Predicate<ChangeData> assignee(String who)
|
||||
throws QueryParseException, IOException, ConfigInvalidException {
|
||||
|
||||
Reference in New Issue
Block a user