Store reviewer field in the index
Prior to this change, draft changes in search results may have resulted in touching the database, since ChangeControl#isDraftVisible checks if the user is a reviewer, and there are not enough stored fields to compute the reviewer set from the index. (We store approvals on the current patch set, not all approvals; even the latter would be insufficient with NoteDb.) Add a new reviewer field that stores enough information to reconstruct the whole ReviewerSet, and also to search by reviewer state. Shove this all in one repeated field with a little comma-separated format, similar to what we already do for labels. The current ReviewerPredicate implementation matches the old behavior of returning results independent of state, although it's now expressed as a predicate tree. Change-Id: Ie54b9e2decf847185ec741bc50bae7eb680787a0
This commit is contained in:
@@ -24,7 +24,9 @@ import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
||||
import static com.google.gerrit.server.index.change.IndexRewriter.CLOSED_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.IndexRewriter.OPEN_STATUSES;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
@@ -117,6 +119,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
private static final String PATCH_SET_FIELD = ChangeField.PATCH_SET.getName();
|
||||
private static final String REVIEWEDBY_FIELD =
|
||||
ChangeField.REVIEWEDBY.getName();
|
||||
private static final String REVIEWER_FIELD = ChangeField.REVIEWER.getName();
|
||||
private static final String HASHTAG_FIELD =
|
||||
ChangeField.HASHTAG_CASE_AWARE.getName();
|
||||
private static final String STAR_FIELD = ChangeField.STAR.getName();
|
||||
@@ -426,6 +429,9 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
if (fields.contains(STAR_FIELD)) {
|
||||
decodeStar(doc, cd);
|
||||
}
|
||||
if (fields.contains(REVIEWER_FIELD)) {
|
||||
decodeReviewers(doc, cd);
|
||||
}
|
||||
return cd;
|
||||
}
|
||||
|
||||
@@ -512,6 +518,19 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
cd.setStars(stars);
|
||||
}
|
||||
|
||||
private void decodeReviewers(Document doc, ChangeData cd) {
|
||||
cd.setReviewers(
|
||||
ChangeField.parseReviewerFieldValues(
|
||||
FluentIterable.of(doc.getFields(REVIEWER_FIELD))
|
||||
.transform(
|
||||
new Function<IndexableField, String>() {
|
||||
@Override
|
||||
public String apply(IndexableField in) {
|
||||
return in.stringValue();
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
private static <T> List<T> decodeProtos(Document doc, String fieldName,
|
||||
ProtobufCodec<T> codec) {
|
||||
BytesRef[] bytesRefs = doc.getBinaryValues(fieldName);
|
||||
|
||||
Reference in New Issue
Block a user