More session re-use, for optimization.
This commit is contained in:
parent
3ba5349bef
commit
eec6e8b8fd
1 changed files with 4 additions and 6 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue