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
This commit is contained in:
Darragh Bailey 2016-12-20 12:38:29 +00:00 committed by Darragh Bailey
parent 42b1cc8850
commit 882eea76d2
1 changed files with 5 additions and 4 deletions

View File

@ -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: