ChangeRebuilderImpl: Have separate event for draft comments

We are about to replace PatchLineComment with a new Comment class that
doesn't know about the comment status. As result published and draft
comments will be handled separately and it's easier if we have
separate events for them.

Change-Id: I513520c94ec253aa14c6218231e6226fbfeb178a
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-09-22 11:16:17 +02:00
parent 2249c68450
commit e24f8b44f9
3 changed files with 69 additions and 15 deletions

View File

@@ -300,7 +300,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
// We will rebuild all events, except for draft comments, in buckets based
// on author and timestamp.
List<Event> events = new ArrayList<>();
Multimap<Account.Id, PatchLineCommentEvent> draftCommentEvents =
Multimap<Account.Id, DraftCommentEvent> draftCommentEvents =
ArrayListMultimap.create();
events.addAll(getHashtagsEvents(change, manager));
@@ -325,11 +325,13 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
patchSetEvents.put(ps.getId(), pse);
events.add(pse);
for (PatchLineComment c : getPatchLineComments(bundle, ps)) {
PatchLineCommentEvent e =
new PatchLineCommentEvent(c, change, ps, patchListCache);
if (c.getStatus() == Status.PUBLISHED) {
CommentEvent e =
new CommentEvent(c, change, ps, patchListCache);
events.add(e.addDep(pse));
} else {
DraftCommentEvent e =
new DraftCommentEvent(c, change, ps, patchListCache);
draftCommentEvents.put(c.getAuthor(), e);
}
}
@@ -376,9 +378,9 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
}
flushEventsToUpdate(manager, el, change);
EventList<PatchLineCommentEvent> plcel = new EventList<>();
EventList<DraftCommentEvent> plcel = new EventList<>();
for (Account.Id author : draftCommentEvents.keys()) {
for (PatchLineCommentEvent e :
for (DraftCommentEvent e :
Ordering.natural().sortedCopy(draftCommentEvents.get(author))) {
if (!plcel.canAdd(e)) {
flushEventsToDraftUpdate(manager, plcel, change);
@@ -490,7 +492,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
}
private void flushEventsToDraftUpdate(NoteDbUpdateManager manager,
EventList<PatchLineCommentEvent> events, Change change)
EventList<DraftCommentEvent> events, Change change)
throws OrmException {
if (events.isEmpty()) {
return;
@@ -501,7 +503,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
newAuthorIdent(events),
events.getWhen());
update.setPatchSetId(events.getPatchSetId());
for (PatchLineCommentEvent e : events) {
for (DraftCommentEvent e : events) {
e.applyDraft(update);
}
manager.add(update);

View File

@@ -0,0 +1,56 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.notedb.rebuild;
import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.PatchLineCommentsUtil;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gwtorm.server.OrmException;
class CommentEvent extends Event {
public final PatchLineComment c;
private final Change change;
private final PatchSet ps;
private final PatchListCache cache;
CommentEvent(PatchLineComment c, Change change, PatchSet ps,
PatchListCache cache) {
super(PatchLineCommentsUtil.getCommentPsId(c), c.getAuthor(),
c.getWrittenOn(), change.getCreatedOn(), c.getTag());
this.c = c;
this.change = change;
this.ps = ps;
this.cache = cache;
}
@Override
boolean uniquePerUpdate() {
return false;
}
@Override
void apply(ChangeUpdate update) throws OrmException {
checkUpdate(update);
if (c.getRevId() == null) {
setCommentRevId(c, cache, change, ps);
}
update.putComment(c);
}
}

View File

@@ -25,13 +25,13 @@ import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gwtorm.server.OrmException;
class PatchLineCommentEvent extends Event {
class DraftCommentEvent extends Event {
public final PatchLineComment c;
private final Change change;
private final PatchSet ps;
private final PatchListCache cache;
PatchLineCommentEvent(PatchLineComment c, Change change, PatchSet ps,
DraftCommentEvent(PatchLineComment c, Change change, PatchSet ps,
PatchListCache cache) {
super(PatchLineCommentsUtil.getCommentPsId(c), c.getAuthor(),
c.getWrittenOn(), change.getCreatedOn(), c.getTag());
@@ -47,12 +47,8 @@ class PatchLineCommentEvent extends Event {
}
@Override
void apply(ChangeUpdate update) throws OrmException {
checkUpdate(update);
if (c.getRevId() == null) {
setCommentRevId(c, cache, change, ps);
}
update.putComment(c);
void apply(ChangeUpdate update) {
throw new UnsupportedOperationException();
}
void applyDraft(ChangeDraftUpdate draftUpdate) throws OrmException {