Update change to invalidate cache after deletion of draft revision

When draft revision is deleted the change is updated only when the
current draft patch set was deleted. That's because new current patch
set field must be updated in the database.  However when non current draft
patch set was deleted no update of the change happen.  That breaks
CS2 as it relies on browser side cached ETag and computation of ETag on
the server side. Because nothing is changed, the ETags are the same and
HTTP status 304 is returned.

Update the change also if non current draft patch set was deleted.

The only alternative to this approach is to decouple draft revision
retrieval from /changes/<id>/detail endpoint.

Bug: issue 2405
Change-Id: I80f2331362ba61306c9436921ebf153b23c3c4bc
(cherry picked from commit a50fa6761f)
This commit is contained in:
David Ostrovsky 2014-01-17 20:34:33 +01:00 committed by David Ostrovsky
parent 38e6f4462c
commit f067fc081a

View File

@ -121,8 +121,11 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
deleteDraftChange(patchSetId);
} else {
if (change.currentPatchSetId().equals(patchSetId)) {
updateCurrentPatchSet(dbProvider.get(), change,
updateChange(dbProvider.get(), change,
previousPatchSetInfo(patchSetId));
} else {
// TODO(davido): find a better way to enforce cache invalidation.
updateChange(dbProvider.get(), change, null);
}
}
}
@ -148,13 +151,15 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
}
}
private static void updateCurrentPatchSet(final ReviewDb db,
private static void updateChange(final ReviewDb db,
final Change change, final PatchSetInfo psInfo)
throws OrmException {
db.changes().atomicUpdate(change.getId(), new AtomicUpdate<Change>() {
@Override
public Change update(Change c) {
c.setCurrentPatchSet(psInfo);
if (psInfo != null) {
c.setCurrentPatchSet(psInfo);
}
ChangeUtil.updated(c);
return c;
}