Fix usage of ChangedFilesByPatchSetCache

This caching didn't work because we created a new instance in the
callback that is invoked per file, rather than creating one instance and
using it for the whole request.

Note, this cache is only relevant when sticky code owner approvals are
enabled.

Change-Id: Ic2357878227e5f1ffac99530f0584d42b7f1ea3b
Signed-off-by: Edwin Kempin <ekempin@google.com>
Reviewed-on: https://gerrit-review.googlesource.com/c/plugins/code-owners/+/430377
Reviewed-by: Patrick Hiesel <hiesel@google.com>
Tested-by: Zuul <zuul-63@gerritcodereview-ci.iam.gserviceaccount.com>
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java
index d0a6da5..6abc820 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheck.java
@@ -360,7 +360,8 @@
 
       CodeOwnerApprovalCheckInput input =
           inputLoaderFactory.create(codeOwnersConfig, codeOwnerResolver, changeNotes).load();
-
+      ChangedFilesByPatchSetCache changedFilesByPatchSetCache =
+          changedFilesByPatchSetCacheFactory.create(codeOwnersConfig, changeNotes);
       return changedFiles
           .getFromDiffCache(
               changeNotes.getProjectName(), changeNotes.getCurrentPatchSet().commitId())
@@ -371,7 +372,7 @@
                       codeOwnerConfigHierarchy,
                       codeOwnerResolver,
                       codeOwnersConfig,
-                      changedFilesByPatchSetCacheFactory.create(codeOwnersConfig, changeNotes),
+                      changedFilesByPatchSetCache,
                       branch,
                       revision.orElse(null),
                       changedFile,
@@ -435,6 +436,8 @@
       CodeOwnerApprovalCheckInput input =
           CodeOwnerApprovalCheckInput.createForComputingOwnedPaths(
               codeOwnersConfig, codeOwnerResolver, changeNotes, accountIds);
+      ChangedFilesByPatchSetCache changedFilesByPatchSetCache =
+          changedFilesByPatchSetCacheFactory.create(codeOwnersConfig, changeNotes);
       return changedFiles.getFromDiffCache(changeNotes.getProjectName(), patchSet.commitId())
           .stream()
           .map(
@@ -443,7 +446,7 @@
                       codeOwnerConfigHierarchy,
                       codeOwnerResolver,
                       codeOwnersConfig,
-                      changedFilesByPatchSetCacheFactory.create(codeOwnersConfig, changeNotes),
+                      changedFilesByPatchSetCache,
                       branch,
                       revision.orElse(null),
                       changedFile,