Merge "Invalidate ListFiles ETag when PatchListKey changes"
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.hash.Hasher;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.gerrit.extensions.common.FileInfo;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
@@ -22,10 +24,10 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.ChildCollection;
|
||||
import com.google.gerrit.extensions.restapi.ETagView;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -38,6 +40,7 @@ import com.google.gerrit.server.change.AccountPatchReviewStore.PatchSetWithRevie
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -90,7 +93,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
return new FileResource(rev, id.get());
|
||||
}
|
||||
|
||||
public static final class ListFiles implements RestReadView<RevisionResource> {
|
||||
public static final class ListFiles implements ETagView<RevisionResource> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ListFiles.class);
|
||||
|
||||
@Option(name = "--base", metaVar = "revision-id")
|
||||
@@ -322,5 +325,15 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
this.parentNum = parentNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getETag(RevisionResource resource) {
|
||||
Hasher h = Hashing.murmur3_128().newHasher();
|
||||
resource.prepareETag(h, resource.getUser());
|
||||
// File list comes from the PatchListCache, so any change to the key or value should
|
||||
// invalidate ETag.
|
||||
h.putLong(PatchListKey.serialVersionUID);
|
||||
return h.hash().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.hash.Hasher;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestResource.HasETag;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
@@ -82,10 +84,15 @@ public class RevisionResource implements RestResource, HasETag {
|
||||
|
||||
@Override
|
||||
public String getETag() {
|
||||
// Conservative estimate: refresh the revision if its parent change has
|
||||
// changed, so we don't have to check whether a given modification affected
|
||||
// this revision specifically.
|
||||
return change.getETag();
|
||||
Hasher h = Hashing.murmur3_128().newHasher();
|
||||
prepareETag(h, getUser());
|
||||
return h.hash().toString();
|
||||
}
|
||||
|
||||
void prepareETag(Hasher h, CurrentUser user) {
|
||||
// Conservative estimate: refresh the revision if its parent change has changed, so we don't
|
||||
// have to check whether a given modification affected this revision specifically.
|
||||
change.prepareETag(h, user);
|
||||
}
|
||||
|
||||
Account.Id getAccountId() {
|
||||
|
Reference in New Issue
Block a user