Reuse existing Repository for refs filtering
The git-refs-filter plugin is meant to be used
for repositories that may have millions of refs
associated with hundreds of thousands of changes.
Opening and closing the repository for every change
to be filtered has a significant performance degradation
which could also bring the entire clone to fail for
timeout.
The Repository object is always the same for the filtering
of all changes and therefore it makes sense to reuse it
instead of wasting CPU cycles in the open/close of the same
repository million of times.
Change-Id: I0e15c6ce53db56486a29a3c009f724f5a92ff300
diff --git a/src/main/java/com/googlesource/gerrit/modules/gitrefsfilter/ForProjectWrapper.java b/src/main/java/com/googlesource/gerrit/modules/gitrefsfilter/ForProjectWrapper.java
index 7d9df89..6136498 100644
--- a/src/main/java/com/googlesource/gerrit/modules/gitrefsfilter/ForProjectWrapper.java
+++ b/src/main/java/com/googlesource/gerrit/modules/gitrefsfilter/ForProjectWrapper.java
@@ -79,7 +79,7 @@
.filter(
(ref) -> {
String refName = ref.getName();
- return (!isChangeRef(refName) || (!isChangeMetaRef(refName) && isOpen(refName)));
+ return (!isChangeRef(refName) || (!isChangeMetaRef(refName) && isOpen(repo, refName)));
})
.collect(Collectors.toList());
}
@@ -92,10 +92,10 @@
return isChangeRef(changeKey) && changeKey.endsWith("/meta");
}
- private boolean isOpen(String refName) {
+ private boolean isOpen(Repository repo, String refName) {
try {
Change.Id changeId = Change.Id.fromRef(refName);
- ChangeNotes changeNotes = changeNotesFactory.create(project, changeId);
+ ChangeNotes changeNotes = changeNotesFactory.create(repo, project, changeId);
return changeNotes.getChange().getStatus().isOpen();
} catch (NoSuchChangeException e) {
logger.atWarning().withCause(e).log(