Add ChangeMessagesUtil to assist with notedb migration
Like ApprovalsUtil, we added an abstraction layer to assist in the migration to notedb. This utility class helps to write to either the notedb or the reviewdb depending on the state of the NotesMigration instance. Additionally, in this change, I modified all callers of ChangeMessageAccess (which uses the ReviewDb) to instead use ChangeMessagesUtil. Change-Id: Id007ed8e01bd1318f70d804124e1f482a77234fd
This commit is contained in:
@@ -74,12 +74,14 @@ import com.google.gerrit.reviewdb.client.PatchSetInfo.ParentInfo;
|
||||
import com.google.gerrit.reviewdb.client.UserIdentity;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.WebLinks;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.gerrit.server.extensions.webui.UiActions;
|
||||
import com.google.gerrit.server.git.LabelNormalizer;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
@@ -88,7 +90,6 @@ import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeData.ChangedLines;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
@@ -100,7 +101,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -108,22 +108,8 @@ import java.util.TreeMap;
|
||||
|
||||
public class ChangeJson {
|
||||
private static final Logger log = LoggerFactory.getLogger(ChangeJson.class);
|
||||
private static final ResultSet<ChangeMessage> NO_MESSAGES =
|
||||
new ResultSet<ChangeMessage>() {
|
||||
@Override
|
||||
public Iterator<ChangeMessage> iterator() {
|
||||
return toList().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChangeMessage> toList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
private static final List<ChangeMessage> NO_MESSAGES =
|
||||
ImmutableList.of();
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
private final LabelNormalizer labelNormalizer;
|
||||
@@ -140,6 +126,7 @@ public class ChangeJson {
|
||||
private final Revisions revisions;
|
||||
private final Provider<WebLinks> webLinks;
|
||||
private final EnumSet<ListChangesOption> options;
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
|
||||
private AccountInfo.Loader accountLoader;
|
||||
|
||||
@@ -159,7 +146,8 @@ public class ChangeJson {
|
||||
DynamicMap<DownloadCommand> downloadCommands,
|
||||
DynamicMap<RestView<ChangeResource>> changeViews,
|
||||
Revisions revisions,
|
||||
Provider<WebLinks> webLinks) {
|
||||
Provider<WebLinks> webLinks,
|
||||
ChangeMessagesUtil cmUtil) {
|
||||
this.db = db;
|
||||
this.labelNormalizer = ln;
|
||||
this.userProvider = user;
|
||||
@@ -174,6 +162,7 @@ public class ChangeJson {
|
||||
this.changeViews = changeViews;
|
||||
this.revisions = revisions;
|
||||
this.webLinks = webLinks;
|
||||
this.cmUtil = cmUtil;
|
||||
options = EnumSet.noneOf(ListChangesOption.class);
|
||||
}
|
||||
|
||||
@@ -642,8 +631,7 @@ public class ChangeJson {
|
||||
private Collection<ChangeMessageInfo> messages(ChangeControl ctl, ChangeData cd,
|
||||
Map<PatchSet.Id, PatchSet> map)
|
||||
throws OrmException {
|
||||
List<ChangeMessage> messages =
|
||||
db.get().changeMessages().byChange(cd.getId()).toList();
|
||||
List<ChangeMessage> messages = cmUtil.byChange(db.get(), cd.notes());
|
||||
if (messages.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -705,18 +693,18 @@ public class ChangeJson {
|
||||
if (userProvider.get().isIdentifiedUser()) {
|
||||
Account.Id self = ((IdentifiedUser) userProvider.get()).getAccountId();
|
||||
for (List<ChangeData> batch : Iterables.partition(all, 50)) {
|
||||
List<ResultSet<ChangeMessage>> m =
|
||||
List<List<ChangeMessage>> m =
|
||||
Lists.newArrayListWithCapacity(batch.size());
|
||||
for (ChangeData cd : batch) {
|
||||
PatchSet.Id ps = cd.change().currentPatchSetId();
|
||||
if (ps != null && cd.change().getStatus().isOpen()) {
|
||||
m.add(db.get().changeMessages().byPatchSet(ps));
|
||||
m.add(cmUtil.byPatchSet(db.get(), cd.notes(), ps));
|
||||
} else {
|
||||
m.add(NO_MESSAGES);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < m.size(); i++) {
|
||||
if (isChangeReviewed(self, batch.get(i), m.get(i).toList())) {
|
||||
if (isChangeReviewed(self, batch.get(i), m.get(i))) {
|
||||
reviewed.add(batch.get(i).getId());
|
||||
}
|
||||
}
|
||||
@@ -728,12 +716,7 @@ public class ChangeJson {
|
||||
private boolean isChangeReviewed(Account.Id self, ChangeData cd,
|
||||
List<ChangeMessage> msgs) throws OrmException {
|
||||
// Sort messages to keep the most recent ones at the beginning.
|
||||
Collections.sort(msgs, new Comparator<ChangeMessage>() {
|
||||
@Override
|
||||
public int compare(ChangeMessage a, ChangeMessage b) {
|
||||
return b.getWrittenOn().compareTo(a.getWrittenOn());
|
||||
}
|
||||
});
|
||||
msgs = ChangeNotes.MESSAGE_BY_TIME.sortedCopy(msgs);
|
||||
|
||||
Account.Id changeOwnerId = cd.change().getOwner();
|
||||
for (ChangeMessage cm : msgs) {
|
||||
|
Reference in New Issue
Block a user