Store the number of unresolved comments in change index
When changes are queried, we want to return the number of unresolved comments with each change. This number should be pre-counted rather than loading all the comments and counting each time. We also add new search operators, which allow user to query by "has:unresolved" and "unresolved:<RELATION><NUMBER>". The 'unresolvedCommentCount' field of 'ChangeData' will be null if 'lazyLoad' is false. Change-Id: I97c6aeb47db48f56f94c5d184dfa36c8d7868cc8
This commit is contained in:
@@ -127,6 +127,8 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
ChangeField.STORED_SUBMIT_RECORD_LENIENT.getName();
|
||||
private static final String SUBMIT_RECORD_STRICT_FIELD =
|
||||
ChangeField.STORED_SUBMIT_RECORD_STRICT.getName();
|
||||
private static final String UNRESOLVED_COMMENT_COUNT_FIELD =
|
||||
ChangeField.UNRESOLVED_COMMENT_COUNT.getName();
|
||||
|
||||
static Term idTerm(ChangeData cd) {
|
||||
return QueryBuilder.intTerm(LEGACY_ID.getName(), cd.getId().get());
|
||||
@@ -467,6 +469,8 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
if (fields.contains(REF_STATE_PATTERN_FIELD)) {
|
||||
decodeRefStatePatterns(doc, cd);
|
||||
}
|
||||
|
||||
decodeUnresolvedCommentCount(doc, cd);
|
||||
return cd;
|
||||
}
|
||||
|
||||
@@ -568,6 +572,14 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
cd.setRefStatePatterns(copyAsBytes(doc.get(REF_STATE_PATTERN_FIELD)));
|
||||
}
|
||||
|
||||
private void decodeUnresolvedCommentCount(
|
||||
ListMultimap<String, IndexableField> doc, ChangeData cd) {
|
||||
IndexableField f = Iterables.getFirst(doc.get(UNRESOLVED_COMMENT_COUNT_FIELD), null);
|
||||
if (f != null && f.numericValue() != null) {
|
||||
cd.setUnresolvedCommentCount(f.numericValue().intValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> List<T> decodeProtos(
|
||||
ListMultimap<String, IndexableField> doc, String fieldName, ProtobufCodec<T> codec) {
|
||||
Collection<IndexableField> fields = doc.get(fieldName);
|
||||
|
||||
Reference in New Issue
Block a user