Fix caching of /detail for modified reviewer lists
Rely only on ETag for change entity caching. The Last-Modified value was derived from the lastUpdatedOn property, which is not always modified when children are updated. When adding or removing reviewers from a change perform a no-op modification of the Change entity. This bumps its rowVersion as a side-effect of the database mutation, causing the ETag to be different on the next read. Change-Id: If480f92b419041e7d62839ab12211058e78f828f
This commit is contained in:
@@ -117,6 +117,15 @@ public class ChangeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void bumpRowVersionNotLastUpdatedOn(Change.Id id, ReviewDb db)
|
||||
throws OrmException {
|
||||
// Empty update of Change to bump rowVersion, changing its ETag.
|
||||
Change c = db.changes().get(id);
|
||||
if (c != null) {
|
||||
db.changes().update(Collections.singleton(c));
|
||||
}
|
||||
}
|
||||
|
||||
public static void updated(final Change c) {
|
||||
c.resetLastUpdatedOn();
|
||||
computeSortKey(c);
|
||||
|
||||
@@ -16,16 +16,12 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestResource.HasETag;
|
||||
import com.google.gerrit.extensions.restapi.RestResource.HasLastModified;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ChangeResource implements RestResource,
|
||||
HasLastModified, HasETag {
|
||||
public class ChangeResource implements RestResource, HasETag {
|
||||
public static final TypeLiteral<RestView<ChangeResource>> CHANGE_KIND =
|
||||
new TypeLiteral<RestView<ChangeResource>>() {};
|
||||
|
||||
@@ -47,11 +43,6 @@ public class ChangeResource implements RestResource,
|
||||
return getControl().getChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getLastModified() {
|
||||
return getChange().getLastUpdatedOn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getETag() {
|
||||
return String.format("%x-%x",
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.change.DeleteReviewer.Input;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -63,6 +64,7 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
|
||||
if (del.isEmpty()) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getChange().getId(), db);
|
||||
db.patchSetApprovals().delete(del);
|
||||
db.commit();
|
||||
} finally {
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval.LabelId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
@@ -81,7 +82,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
private final Provider<GroupsCollection> groupsCollection;
|
||||
private final GroupMembers.Factory groupMembersFactory;
|
||||
private final AccountInfo.Loader.Factory accountLoaderFactory;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final IdentifiedUser currentUser;
|
||||
private final IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
private final Config cfg;
|
||||
@@ -109,7 +110,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
this.groupsCollection = groupsCollection;
|
||||
this.groupMembersFactory = groupMembersFactory;
|
||||
this.accountLoaderFactory = accountLoaderFactory;
|
||||
this.db = db;
|
||||
this.dbProvider = db;
|
||||
this.currentUser = currentUser;
|
||||
this.identifiedUserFactory = identifiedUserFactory;
|
||||
this.cfg = cfg;
|
||||
@@ -215,9 +216,10 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
return;
|
||||
}
|
||||
|
||||
ReviewDb db = dbProvider.get();
|
||||
PatchSet.Id psid = rsrc.getChange().currentPatchSetId();
|
||||
Set<Account.Id> existing = Sets.newHashSet();
|
||||
for (PatchSetApproval psa : db.get().patchSetApprovals().byPatchSet(psid)) {
|
||||
for (PatchSetApproval psa : db.patchSetApprovals().byPatchSet(psid)) {
|
||||
existing.add(psa.getAccountId());
|
||||
}
|
||||
|
||||
@@ -235,7 +237,19 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
new ReviewerInfo(id), control, ImmutableList.of(psa)));
|
||||
toInsert.add(psa);
|
||||
}
|
||||
db.get().patchSetApprovals().insert(toInsert);
|
||||
if (toInsert.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.changes().beginTransaction(rsrc.getChange().getId());
|
||||
try {
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getChange().getId(), db);
|
||||
db.patchSetApprovals().insert(toInsert);
|
||||
db.commit();
|
||||
} finally {
|
||||
db.rollback();
|
||||
}
|
||||
|
||||
accountLoaderFactory.create(true).fill(result.reviewers);
|
||||
postAdd(rsrc.getChange(), result);
|
||||
}
|
||||
@@ -248,10 +262,10 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
|
||||
// Execute hook for added reviewers
|
||||
//
|
||||
PatchSet patchSet = db.get().patchSets().get(change.currentPatchSetId());
|
||||
PatchSet patchSet = dbProvider.get().patchSets().get(change.currentPatchSetId());
|
||||
for (AccountInfo info : result.reviewers) {
|
||||
Account account = accountCache.get(info._id).getAccount();
|
||||
hooks.doReviewerAddedHook(change, account, patchSet, db.get());
|
||||
hooks.doReviewerAddedHook(change, account, patchSet, dbProvider.get());
|
||||
}
|
||||
|
||||
// Email the reviewers
|
||||
|
||||
Reference in New Issue
Block a user