Add alwaysShowButton configuration variable.

Set it to true if a Gerrit server is too slow to open many CLs.

Change-Id: I0188d2b8f2b97f62f1744450bf26c31044d2a416
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
index 80fa81d..834994e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
@@ -194,23 +194,28 @@
   @Override
   public Description getDescription(RevisionResource resource) {
     Change change = resource.getChangeResource().getChange();
-    try (ReviewDb reviewDb = reviewDbProvider.open();
-        Repository repo = repoManager.openRepository(change.getProject())) {
+    try (ReviewDb reviewDb = reviewDbProvider.open()) {
       ChangeData changeData = changeDataFactory.create(reviewDb, change);
       if (changeData.change().getDest().get() == null) {
         log.error("Cannot get branch of change: " + changeData.getId().get());
         return null; // no "Find Owners" button
       }
-      OwnersDb db = Cache.getInstance().get(repo, changeData);
-      log.trace("getDescription db key = " + db.key);
       Status status = resource.getChange().getStatus();
       // Commit message is not used to enable/disable "Find Owners".
       boolean needFindOwners =
           userProvider != null
               && userProvider.get() instanceof IdentifiedUser
-              && (db.getNumOwners() > 0)
               && status != Status.ABANDONED
               && status != Status.MERGED;
+      // If alwaysShowButton is true, skip expensive owner lookup.
+      if (needFindOwners && !Config.getAlwaysShowButton()) {
+        needFindOwners = false; // Show button only if some owner is found.
+        try (Repository repo = repoManager.openRepository(change.getProject())) {
+          OwnersDb db = Cache.getInstance().get(repo, changeData);
+          log.trace("getDescription db key = " + db.key);
+          needFindOwners = db.getNumOwners() > 0;
+        }
+      }
       return new Description()
           .setLabel("Find Owners")
           .setTitle("Find owners to add to Reviewers list")
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
index 32fab27..cdf9d56 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
@@ -33,6 +33,7 @@
   static final String MAX_CACHE_AGE = "maxCacheAge"; // seconds to stay in cache
   static final String MAX_CACHE_SIZE = "maxCacheSize"; // number of OwnersDb in cache
   static final String REPORT_SYNTAX_ERROR = "reportSyntaxError";
+  static final String ALWAYS_SHOW_BUTTON = "alwaysShowButton"; // always show "Find Owners" button
   static final String PLUGIN_NAME = "find-owners";
   static final String PROLOG_NAMESPACE = "find_owners";
 
@@ -43,6 +44,7 @@
   private static int maxCacheAge = 0;
   private static int maxCacheSize = 1000;
   private static boolean reportSyntaxError = false;
+  private static boolean alwaysShowButton = false;
 
   private static final Logger log = LoggerFactory.getLogger(Config.class);
 
@@ -55,6 +57,7 @@
     // Get config variables from the plugin section of gerrit.config
     addDebugMsg = gc.getBoolean(ADD_DEBUG_MSG, false);
     reportSyntaxError = gc.getBoolean(REPORT_SYNTAX_ERROR, false);
+    alwaysShowButton = gc.getBoolean(ALWAYS_SHOW_BUTTON, false);
     minOwnerVoteLevel = gc.getInt(MIN_OWNER_VOTE_LEVEL, 1);
     maxCacheAge = gc.getInt(MAX_CACHE_AGE, 0);
     maxCacheSize = gc.getInt(MAX_CACHE_SIZE, 1000);
@@ -76,6 +79,10 @@
     return reportSyntaxError;
   }
 
+  static boolean getAlwaysShowButton() {
+    return alwaysShowButton;
+  }
+
   @VisibleForTesting
   static void setReportSyntaxError(boolean value) {
     reportSyntaxError = value;