ChangeRebuilderImpl: Properly filter PatchLineComments

In I1158855f I accidentally replaced db.patchComments().byPatchSet(id)
with bundle.getPatchLineComments(), which erroneously tried to apply
every comment event to every patch set. Fix this by filtering the
list explicitly.

Change-Id: Ic78db29259debaf903e9c471e87a922d18dfac28
This commit is contained in:
Dave Borowitz
2016-04-07 09:57:23 -04:00
parent 001504f1b7
commit 5a18df0286

View File

@@ -22,9 +22,11 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@@ -189,10 +191,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
for (PatchSet ps : bundle.getPatchSets()) {
events.add(new PatchSetEvent(change, ps, manager.getCodeRepo().rw));
List<PatchLineComment> comments =
PatchLineCommentsUtil.PLC_ORDER.sortedCopy(
bundle.getPatchLineComments());
for (PatchLineComment c : comments) {
for (PatchLineComment c : getPatchLineComments(bundle, ps)) {
PatchLineCommentEvent e =
new PatchLineCommentEvent(c, change, ps, patchListCache);
if (c.getStatus() == Status.PUBLISHED) {
@@ -240,6 +239,17 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
}
}
private static List<PatchLineComment> getPatchLineComments(ChangeBundle bundle,
final PatchSet ps) {
return FluentIterable.from(bundle.getPatchLineComments())
.filter(new Predicate<PatchLineComment>() {
@Override
public boolean apply(PatchLineComment in) {
return in.getPatchSetId().equals(ps.getId());
}
}).toSortedList(PatchLineCommentsUtil.PLC_ORDER);
}
private void flushEventsToUpdate(NoteDbUpdateManager manager,
EventList<Event> events, Change change)
throws NoSuchChangeException, OrmException, IOException {