Remove drafts and stars from the ref_state_pattern index field
Change I36c1e2f56127a7e5a11769bf36daf586e32d8bcf excluded drafts and
stars from the ref_state index field but failed to exclude the related
patterns from the ref_state_pattern. As a result, any change that had a
draft comment or a star was always stale, reindexing such a change would
never get it out of the stale state.
Release-Notes: Fix change staleness check for changes with drafts and stars
Forward-Compatible: checked
Change-Id: Ie66138180f3df65c82624905ecdab915992b381b
diff --git a/java/com/google/gerrit/server/index/change/ChangeField.java b/java/com/google/gerrit/server/index/change/ChangeField.java
index d3f6268..01a19df 100644
--- a/java/com/google/gerrit/server/index/change/ChangeField.java
+++ b/java/com/google/gerrit/server/index/change/ChangeField.java
@@ -70,7 +70,6 @@
import com.google.gerrit.server.ReviewerByEmailSet;
import com.google.gerrit.server.ReviewerSet;
import com.google.gerrit.server.StarredChangesUtil;
-import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.index.change.StalenessChecker.RefStatePattern;
import com.google.gerrit.server.notedb.ReviewerStateInternal;
import com.google.gerrit.server.notedb.SubmitRequirementProtoConverter;
@@ -1362,12 +1361,6 @@
RefStatePattern.create(
RefNames.REFS_USERS + "*/" + RefNames.EDIT_PREFIX + id + "/*")
.toByteArray(project));
- result.add(
- RefStatePattern.create(RefNames.refsStarredChangesPrefix(id) + "*")
- .toByteArray(allUsers(cd)));
- result.add(
- RefStatePattern.create(RefNames.refsDraftCommentsPrefix(id) + "*")
- .toByteArray(allUsers(cd)));
return result;
},
(cd, field) -> cd.setRefStatePatterns(field));
@@ -1404,10 +1397,6 @@
return in -> in.change() != null ? func.apply(in.change()) : null;
}
- private static AllUsersName allUsers(ChangeData cd) {
- return cd.getAllUsersNameForIndexing();
- }
-
private static String truncateStringValueToMaxTermLength(String str) {
return truncateStringValue(str, MAX_TERM_LENGTH);
}
diff --git a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
index f6e7ede..ca7d540 100644
--- a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
+++ b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
@@ -3297,6 +3297,14 @@
assertQuery("has:edit", change);
assertThat(indexer.reindexIfStale(project, change.getId()).get()).isTrue();
assertQuery("has:edit");
+
+ // Index is not stale when a draft comment exists
+ DraftInput in = new DraftInput();
+ in.line = 1;
+ in.message = "nit: trailing whitespace";
+ in.path = Patch.COMMIT_MSG;
+ gApi.changes().id(project.get(), change.getId().get()).current().createDraft(in);
+ assertThat(indexer.reindexIfStale(project, change.getId()).get()).isFalse();
}
@Test