Cache DefaultRefFilter to speed up subsequent filter() calls
DefaultRefFilter has a Map of visible changes as internal state. Reusing
this map in subsequent calls speeds the operation up.
Change-Id: Idb8627138badfeb3182b5904c3d569789334366c
diff --git a/java/com/google/gerrit/server/permissions/ProjectControl.java b/java/com/google/gerrit/server/permissions/ProjectControl.java
index cd84950..531d145 100644
--- a/java/com/google/gerrit/server/permissions/ProjectControl.java
+++ b/java/com/google/gerrit/server/permissions/ProjectControl.java
@@ -317,6 +317,7 @@
}
private class ForProjectImpl extends ForProject {
+ private DefaultRefFilter refFilter;
private String resourcePath;
@Override
@@ -389,7 +390,10 @@
@Override
public Map<String, Ref> filter(Map<String, Ref> refs, Repository repo, RefFilterOptions opts)
throws PermissionBackendException {
- return refFilterFactory.create(ProjectControl.this).filter(refs, repo, opts);
+ if (refFilter == null) {
+ refFilter = refFilterFactory.create(ProjectControl.this);
+ }
+ return refFilter.filter(refs, repo, opts);
}
private boolean can(ProjectPermission perm) throws PermissionBackendException {