Reuse the already opened Repository for refs filtering

Gerrit needs to access the Change status for refs filtering
for hiding the private ones.
Reuse the Repository already opened for the fetching of
all changes avoiding the open/close of the same one
for every single change.

Change-Id: I8796d17e4d3876835392b4132f22d1821b2840d7
diff --git a/java/com/google/gerrit/server/permissions/DefaultRefFilter.java b/java/com/google/gerrit/server/permissions/DefaultRefFilter.java
index eca30b6..03d3b63 100644
--- a/java/com/google/gerrit/server/permissions/DefaultRefFilter.java
+++ b/java/com/google/gerrit/server/permissions/DefaultRefFilter.java
@@ -142,7 +142,7 @@
         return ImmutableList.of();
       }
       if (RefNames.isRefsChanges(refName)) {
-        boolean isChangeRefVisisble = canSeeSingleChangeRef(refName);
+        boolean isChangeRefVisisble = canSeeSingleChangeRef(repo, refName);
         if (isChangeRefVisisble) {
           logger.atFinest().log("Change ref %s is visible", refName);
           return refs;
@@ -466,7 +466,8 @@
    * with refs-in-wants is used as that enables Gerrit to skip traditional advertisement of all
    * visible refs.
    */
-  private boolean canSeeSingleChangeRef(String refName) throws PermissionBackendException {
+  private boolean canSeeSingleChangeRef(Repository repo, String refName)
+      throws PermissionBackendException {
     // We are treating just a single change ref. We are therefore not going through regular ref
     // filtering, but use NoteDb directly. This makes it so that we can always serve this ref
     // even if the change is not part of the set of most recent changes that
@@ -480,7 +481,7 @@
     }
     ChangeNotes notes;
     try {
-      notes = changeNotesFactory.create(projectState.getNameKey(), cId);
+      notes = changeNotesFactory.create(repo, projectState.getNameKey(), cId);
     } catch (StorageException e) {
       throw new PermissionBackendException("can't construct change notes", e);
     }