Bump Change.lastUpdatedOn when adding reviewers

The agreement in a recent discussion[1] was that we want to add
ChangeMessages when adding reviewers to a change. At that point, we
would bump the lasUpdatedOn field in Change, since we always do that
when adding ChangeMessages. Thus there is no real reason to *not* bump
lastUpdatedOn when adding a reviewer; go ahead and do that now. (This
change is just about lastUpdatedOn, and does not actually add that
message.)

This change removes the only place other than draft comments where we
modify a change but don't bump lastUpdatedOn. We still need to deal
with converting old ReviewDb changes to NoteDb where there might be
entities in the bundle that are newer than the lastUpdatedOn
timestamp. Don't worry about messing around with timestamps in NoteDb;
instead just use the latest timestamp from across the whole entity
group (excluding draft comments) when comparing to a ReviewDb
ChangeBundle. This should get us the same results in NoteDb from
reading just the change meta graph.

[1] https://groups.google.com/d/topic/repo-discuss/aULNkde4DKc/discussion

Change-Id: I51978a0234b9c70d9d84a16fc7d30477bf6e3596
This commit is contained in:
Dave Borowitz
2016-04-29 09:53:43 -04:00
parent f5dc67d45d
commit 1e20979bdb
6 changed files with 118 additions and 38 deletions

View File

@@ -117,7 +117,7 @@ public class ChangeBundleTest {
"changeId differs for Changes: {" + id1 + "} != {" + id2 + "}",
"createdOn differs for Changes:"
+ " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:06.0}",
"lastUpdatedOn differs for Changes:"
"effective last updated time differs for Changes:"
+ " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:06.0}");
}
@@ -155,7 +155,7 @@ public class ChangeBundleTest {
assertDiffs(b1, b2,
"createdOn differs for Change.Id " + c1.getId() + ":"
+ " {2009-09-30 17:00:01.0} != {2009-09-30 17:00:02.0}",
"lastUpdatedOn differs for Change.Id " + c1.getId() + ":"
"effective last updated time differs for Change.Id " + c1.getId() + ":"
+ " {2009-09-30 17:00:01.0} != {2009-09-30 17:00:03.0}");
// One NoteDb, slop is allowed.
@@ -174,8 +174,8 @@ public class ChangeBundleTest {
comments(), NOTE_DB);
ChangeBundle b3 = new ChangeBundle(c3, messages(), patchSets(), approvals(),
comments(), REVIEW_DB);
String msg = "lastUpdatedOn differs for Change.Id " + c1.getId()
+ " in NoteDb vs. ReviewDb:"
String msg = "effective last updated time differs for Change.Id "
+ c1.getId() + " in NoteDb vs. ReviewDb:"
+ " {2009-09-30 17:00:01.0} != {2009-09-30 17:00:10.0}";
assertDiffs(b1, b3, msg);
assertDiffs(b3, b1, msg);
@@ -272,6 +272,35 @@ public class ChangeBundleTest {
+ " {topic} != {null}");
}
@Test
public void diffChangesTakesMaxEntityTimestampFromReviewDb()
throws Exception {
Change c1 = TestChanges.newChange(
new Project.NameKey("project"), new Account.Id(100));
PatchSetApproval a = new PatchSetApproval(
new PatchSetApproval.Key(
c1.currentPatchSetId(), accountId, new LabelId("Code-Review")),
(short) 1,
TimeUtil.nowTs());
Change c2 = clone(c1);
c2.setLastUpdatedOn(a.getGranted());
// Both ReviewDb, exact match required.
ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(),
approvals(a), comments(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(),
approvals(a), comments(), REVIEW_DB);
assertDiffs(b1, b2,
"effective last updated time differs for Change.Id " + c1.getId() + ":"
+ " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:06.0}");
// NoteDb allows latest timestamp from all entities in bundle.
b2 = new ChangeBundle(c2, messages(), patchSets(),
approvals(a), comments(), NOTE_DB);
assertNoDiffs(b1, b2);
}
@Test
public void diffChangeMessageKeySets() throws Exception {
Change c = TestChanges.newChange(project, accountId);

View File

@@ -728,18 +728,17 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Timestamp ts7 = newNotes(c).getChange().getLastUpdatedOn();
assertThat(ts7).isGreaterThan(ts6);
// Updates that should not touch the timestamp.
update = newUpdate(c, changeOwner);
update.putReviewer(otherUser.getAccountId(), ReviewerStateInternal.REVIEWER);
update.commit();
Timestamp ts8 = newNotes(c).getChange().getLastUpdatedOn();
assertThat(ts8).isEqualTo(ts7);
assertThat(ts8).isGreaterThan(ts7);
update = newUpdate(c, changeOwner);
update.setGroups(ImmutableList.of("a", "b"));
update.commit();
Timestamp ts9 = newNotes(c).getChange().getLastUpdatedOn();
assertThat(ts9).isEqualTo(ts8);
assertThat(ts9).isGreaterThan(ts8);
// Finish off by merging the change.
update = newUpdate(c, changeOwner);