Skip to content

Commit

Permalink
Simplify calls to executor.submit()
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Nov 5, 2023
1 parent 9227124 commit 4a5b941
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,12 @@ def _get_user_issues2( # pylint: disable=too-many-arguments
assigned = created = True
issues: list[Issue] = []

def get_assigned_issues() -> list[Issue]:
return self.get_assigned(username, **kwargs)

def get_created_issues() -> list[Issue]:
return self.get_created(username, **kwargs)

futures = []
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
futures.append(executor.submit(get_assigned_issues))
futures.append(executor.submit(self.get_assigned, username, **kwargs))
if created:
futures.append(executor.submit(get_created_issues))
futures.append(executor.submit(self.get_created, username, **kwargs))
for future in concurrent.futures.as_completed(futures):
issues.extend(future.result())

Expand All @@ -229,19 +223,30 @@ def _get_user_issues4( # pylint: disable=too-many-arguments
assigned = created = True
issues: list[Issue] = []

def get_issues(is_pr: bool, is_assigned: bool) -> list[Issue]:
if is_assigned:
return self.get_assigned(username, pull_requests=is_pr, **kwargs)
return self.get_created(username, pull_requests=is_pr, **kwargs)

futures = []
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
if assigned:
futures.append(executor.submit(get_issues, False, True))
futures.append(executor.submit(get_issues, True, True))
futures.append(
executor.submit(
self.get_assigned, username, pull_requests=False, **kwargs
)
)
futures.append(
executor.submit(
self.get_assigned, username, pull_requests=True, **kwargs
)
)
if created:
futures.append(executor.submit(get_issues, False, False))
futures.append(executor.submit(get_issues, True, False))
futures.append(
executor.submit(
self.get_created, username, pull_requests=False, **kwargs
)
)
futures.append(
executor.submit(
self.get_created, username, pull_requests=True, **kwargs
)
)
for future in concurrent.futures.as_completed(futures):
issues.extend(future.result())

Expand Down

0 comments on commit 4a5b941

Please sign in to comment.