roll_util: Skip reviewer query for large rolls

Skip querying for owner/reviewer on rolled CLs if there are too many CLs
in the roll.

Change-Id: I6d0d190067ef3c7c8ee83b8211e7c3eddaf0c116
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/52782
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Ina Huh <ihuh@google.com>
diff --git a/recipe_modules/roll_util/api.py b/recipe_modules/roll_util/api.py
index f1c7220..036e655 100644
--- a/recipe_modules/roll_util/api.py
+++ b/recipe_modules/roll_util/api.py
@@ -140,12 +140,14 @@
 
                 log_kwargs = {'stdout': self._api.raw_io.output()}
 
-                commits = []
-                for commit in (
+                commit_log = (
                     self._api.git('git log', *log_cmd, **log_kwargs)
                     .stdout.strip('\0')
                     .split('\0')
-                ):
+                )
+
+                commits = []
+                for i, commit in enumerate(commit_log):
                     hash, author, message = commit.split('\n', 2)
                     owner = None
                     reviewers = []
@@ -154,14 +156,20 @@
                         self.gerrit_name
                     )
 
-                    changes = self._api.gerrit.change_query(
-                        'get change-id',
-                        'commit:{}'.format(hash),
-                        host=full_host,
-                        test_data=self._api.json.test_api.output(
-                            [{'_number': 12345}]
-                        ),
-                    ).json.output
+                    changes = []
+
+                    # If there are a lot of CLs in this roll only get owner and
+                    # reviewer data from the first 10 so we don't make too many
+                    # requests of Gerrit.
+                    if i < 10:
+                        changes = self._api.gerrit.change_query(
+                            'get change-id',
+                            'commit:{}'.format(hash),
+                            host=full_host,
+                            test_data=self._api.json.test_api.output(
+                                [{'_number': 12345}]
+                            ),
+                        ).json.output
 
                     if changes and len(changes) == 1:
                         number = changes[0]['_number']