Add a JSON version number to the ChangeResource ETag

I62aecac9 added a new field to ChangeInfo that is populated on all
requests, and this field is now required to render the submit strategy
on the change screen. Unfortunately, this didn't change the ETag of
existing change resources, so browsers with cached old ChangeInfo will
not see the submit type until the change is updated or the cache is
refreshed.

Try to prevent this in the future by encouraging developers to bump a
version number to invalidate existing ETags.

Change-Id: I8bf93ba570a43a1118b584e8e83860c48274c1da
This commit is contained in:
Dave Borowitz
2016-01-07 12:05:27 -05:00
parent d9141ef46a
commit 2a67711f96

View File

@@ -34,6 +34,14 @@ import com.google.inject.TypeLiteral;
import org.eclipse.jgit.lib.ObjectId;
public class ChangeResource implements RestResource, HasETag {
/**
* JSON format version number for ETag computations.
* <p>
* Should be bumped on any JSON format change (new fields, etc.) so that
* otherwise unmodified changes get new ETags.
*/
public static final int JSON_FORMAT_VERSION = 1;
public static final TypeLiteral<RestView<ChangeResource>> CHANGE_KIND =
new TypeLiteral<RestView<ChangeResource>>() {};
@@ -74,7 +82,8 @@ public class ChangeResource implements RestResource, HasETag {
// This includes all information relevant for ETag computation
// unrelated to the UI.
public void prepareETag(Hasher h, CurrentUser user) {
h.putLong(getChange().getLastUpdatedOn().getTime())
h.putInt(JSON_FORMAT_VERSION)
.putLong(getChange().getLastUpdatedOn().getTime())
.putInt(getChange().getRowVersion())
.putInt(user.isIdentifiedUser() ? user.getAccountId().get() : 0);