Use PerThreadCache to create code-owners plugin config only once per request

Each call of CodeOwnersPluginConfiguration#getProjectConfig causes a
load of the plugin config with inheritance via
pluginConfigFactory#getProjectPluginConfigWithInheritance(projectName,
pluginName) which is not free. CodeOwnersPluginConfigSnapshot that is
returned by CodeOwnersPluginConfiguration#getProjectConfig caches the
plugin config, hence creating CodeOwnersPluginConfigSnapshot only once
and reading multiple config param from it is more efficient. Reduce the
number of CodeOwnersPluginConfiguration#getProjectConfig calls by
caching CodeOwnersPluginConfigSnapshort in the PerThreadCache so that
the code-owners plugin config is only created once per request.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: If541bc32929996b3af19ba1ad0709946aa04ffbb
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfiguration.java b/java/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfiguration.java
index f833542..0855baf 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfiguration.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfiguration.java
@@ -22,6 +22,7 @@
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
+import com.google.gerrit.server.cache.PerThreadCache;
 import com.google.gerrit.server.config.PluginConfigFactory;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -72,7 +73,9 @@
    */
   public CodeOwnersPluginConfigSnapshot getProjectConfig(Project.NameKey projectName) {
     requireNonNull(projectName, "projectName");
-    return codeOwnersPluginConfigSnapshotFactory.create(projectName);
+    return PerThreadCache.getOrCompute(
+        PerThreadCache.Key.create(CodeOwnersPluginConfigSnapshot.class, projectName),
+        () -> codeOwnersPluginConfigSnapshotFactory.create(projectName));
   }
 
   /**