From 882eea76d2d0c6d7415991796aadca0e95d51866 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Tue, 20 Dec 2016 12:38:29 +0000 Subject: [PATCH] Skip retry loop on first check for group Don't retry checking the DB multiple times on first call to see if group exists when determining whether the group needs to be created. If the group exists, a previous iteration would already have waited for the group to be written down from the cache. So if nothing is returned then the group does not exist, and there is no point rechecking multiple times to see if it will appear from the cache. This speeds up creation of new groups by avoiding a 10 second wait before creation due to the first call for group uuid unnecessarily retrying multiple times. Change-Id: I0afbc716159e8aecf1ade6442d9b02674094fa08 --- jeepyb/cmd/manage_projects.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py index 878a4a8..3474e2b 100644 --- a/jeepyb/cmd/manage_projects.py +++ b/jeepyb/cmd/manage_projects.py @@ -211,7 +211,7 @@ def push_acl_config(project, remote_url, repo_path, gitid, env=None): return True -def _get_group_uuid(group): +def _get_group_uuid(group, retries=10): """ Gerrit keeps internal user groups in the DB while it keeps systems groups in All-Projects groups file (in refs/meta/config). This @@ -224,7 +224,7 @@ def _get_group_uuid(group): """ query = "SELECT group_uuid FROM account_groups WHERE name = %s" con = jeepyb.gerritdb.connect() - for x in range(10): + for x in range(retries): cursor = con.cursor() cursor.execute(query, (group,)) data = cursor.fetchone() @@ -232,12 +232,13 @@ def _get_group_uuid(group): con.commit() if data: return data[0] - time.sleep(1) + if retries > 1: + time.sleep(1) return None def get_group_uuid(gerrit, group): - uuid = _get_group_uuid(group) + uuid = _get_group_uuid(group, retries=1) if uuid: return uuid if group in GERRIT_SYSTEM_GROUPS: