From eec6e8b8fdd0cf21fdab25aae2d1209d0048448f Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Fri, 11 Aug 2017 17:49:10 +0000 Subject: [PATCH] More session re-use, for optimization. --- roles/bodhi2/backend/templates/owner-sync-pagure.j2 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/roles/bodhi2/backend/templates/owner-sync-pagure.j2 b/roles/bodhi2/backend/templates/owner-sync-pagure.j2 index 50c2bc8639..cc67dddd5f 100755 --- a/roles/bodhi2/backend/templates/owner-sync-pagure.j2 +++ b/roles/bodhi2/backend/templates/owner-sync-pagure.j2 @@ -162,7 +162,7 @@ def get_repo_name_and_arches(tag, version): return repo_name, arches -def get_pagure_project_name_and_branch(namespace, project_name): +def get_pagure_project_name_and_branch(session, namespace, project_name): """ Gets the branches on a project. This function is used for mapping. :param namespace: string of the namespace the project is in @@ -170,7 +170,6 @@ def get_pagure_project_name_and_branch(namespace, project_name): :return: a tuple containing the string of the project and a list of branches """ - session = retry_session() project_branches_url = '{0}api/0/{1}/{2}/git/branches'.format( PAGURE_URL, namespace, project_name) project_branches_rv = session.get( @@ -184,7 +183,7 @@ def get_pagure_project_name_and_branch(namespace, project_name): return project_name, project_branches_rv.json()['branches'] -def get_pagure_project_names_from_page(namespace, page): +def get_pagure_project_names_from_page(session, namespace, page): """ Gets the names of all the Pagure projects on a page. This function is to be used for mapping. @@ -194,7 +193,6 @@ def get_pagure_project_names_from_page(namespace, page): """ url = urljoin(PAGURE_URL, 'api/0/projects?namespace={0}'.format(namespace)) url = url + '&page={0}&per_page=100&fork=false&short=true'.format(page) - session = retry_session() response = session.get(url, verify=VERIFY, timeout=120) if not bool(response): print("Failed to talk to %r %r." % ( @@ -230,7 +228,7 @@ def get_pagure_project_branches(namespace): # Since we are going to multi-thread, we need to make a partial function # call so that all the function needs is an iterable to run partial_get_pagure_projects_page = partial( - get_pagure_project_names_from_page, namespace) + get_pagure_project_names_from_page, session, namespace) project_names_sets = pool.map(partial_get_pagure_projects_page, range(1, num_pages + 1)) @@ -245,7 +243,7 @@ def get_pagure_project_branches(namespace): # Since we are going to multi-thread, we need to make a partial function # call so that all the function needs is an iterable to run partial_get_pagure_project_name_and_branch = partial( - get_pagure_project_name_and_branch, namespace) + get_pagure_project_name_and_branch, session, namespace) # Get a list of tuples in the form of (project, [branch...]), then convert # that to a dictionary project_names_to_branches = dict(pool.map(