Skip to content

Commit

Permalink
Use multithreading to get assigned & created issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 19, 2023
1 parent f769602 commit 71c5775
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 38 deletions.
24 changes: 16 additions & 8 deletions services/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
from concurrent.futures import ThreadPoolExecutor
from typing import Any

from bugzilla import Bugzilla # type: ignore
Expand Down Expand Up @@ -89,16 +90,23 @@ def get_user_issues( # pylint: disable=too-many-arguments
if involved:
assigned = created = True
issues: list[Issue] = []
if assigned:

def get_assigned_issues():
more = self.get_assigned(username, closed=closed)
if more is None:
return None
issues.extend(more)
if created:
if more is not None:
issues.extend(more)

def get_created_issues():
more = self.get_created(username, closed=closed)
if more is None:
return None
issues.extend(more)
if more is not None:
issues.extend(more)

with ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
executor.submit(get_assigned_issues)
if created:
executor.submit(get_created_issues)

return list(set(issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
Expand Down
33 changes: 26 additions & 7 deletions services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
from concurrent.futures import ThreadPoolExecutor
from typing import Any
from urllib.parse import urlparse

Expand Down Expand Up @@ -112,18 +113,36 @@ def get_user_issues( # pylint: disable=too-many-arguments
if involved:
assigned = created = True
issues: list[Issue] = []
if assigned:
for is_pr in (False, True):

def get_issues(is_pr: bool, is_assigned: bool):
if is_assigned:
more = self.get_assigned(username, pull_requests=is_pr, state=state)
if more is None:
return None
issues.extend(more)
if created:
for is_pr in (False, True):
else:
more = self.get_created(username, pull_requests=is_pr, state=state)
return more

with ThreadPoolExecutor(max_workers=4) as executor:
futures = []
if assigned:
futures.append(
executor.submit(get_issues, False, True)
) # Get assigned non-PR issues
futures.append(
executor.submit(get_issues, True, True)
) # Get assigned PR issues
if created:
futures.append(
executor.submit(get_issues, False, False)
) # Get created non-PR issues
futures.append(
executor.submit(get_issues, True, False)
) # Get created PR issues
for future in futures:
more = future.result()
if more is None:
return None
issues.extend(more)

return list(set(issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
Expand Down
24 changes: 16 additions & 8 deletions services/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import logging
from concurrent.futures import ThreadPoolExecutor
from typing import Any
from urllib.parse import urlparse

Expand Down Expand Up @@ -88,16 +89,23 @@ def get_user_issues( # pylint: disable=too-many-arguments
if involved:
assigned = created = True
issues: list[Issue] = []
if assigned:

def get_assigned_issues():
more = self.get_assigned(username)
if more is None:
return None
issues.extend(more)
if created:
if more is not None:
issues.extend(more)

def get_created_issues():
more = self.get_created(username)
if more is None:
return None
issues.extend(more)
if more is not None:
issues.extend(more)

with ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
executor.submit(get_assigned_issues)
if created:
executor.submit(get_created_issues)

return list(set(issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
Expand Down
33 changes: 26 additions & 7 deletions services/pagure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import logging
from concurrent.futures import ThreadPoolExecutor
from typing import Any

from requests.exceptions import RequestException
Expand Down Expand Up @@ -128,18 +129,36 @@ def get_user_issues( # pylint: disable=too-many-arguments
if involved:
assigned = created = True
issues: list[Issue] = []
if assigned:
for is_pr in (False, True):

def get_issues(is_pr: bool, is_assigned: bool):
if is_assigned:
more = self.get_assigned(username, pull_requests=is_pr, state=state)
if more is None:
return None
issues.extend(more)
if created:
for is_pr in (False, True):
else:
more = self.get_created(username, pull_requests=is_pr, state=state)
return more

with ThreadPoolExecutor(max_workers=4) as executor:
futures = []
if assigned:
futures.append(
executor.submit(get_issues, False, True)
) # Get assigned non-PR issues
futures.append(
executor.submit(get_issues, True, True)
) # Get assigned PR issues
if created:
futures.append(
executor.submit(get_issues, False, False)
) # Get created non-PR issues
futures.append(
executor.submit(get_issues, True, False)
) # Get created PR issues
for future in futures:
more = future.result()
if more is None:
return None
issues.extend(more)

return list(set(issues))

def _to_issue(self, info: Any, **kwargs) -> Issue:
Expand Down
24 changes: 16 additions & 8 deletions services/redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
from concurrent.futures import ThreadPoolExecutor
from typing import Any

from redminelib import Redmine # type: ignore
Expand Down Expand Up @@ -74,16 +75,23 @@ def get_user_issues( # pylint: disable=too-many-arguments
if involved:
assigned = created = True
issues: list[Issue] = []
if assigned:

def get_assigned_issues():
more = self.get_assigned(username)
if more is None:
return None
issues.extend(more)
if created:
if more is not None:
issues.extend(more)

def get_created_issues():
more = self.get_created(username)
if more is None:
return None
issues.extend(more)
if more is not None:
issues.extend(more)

with ThreadPoolExecutor(max_workers=2) as executor:
if assigned:
executor.submit(get_assigned_issues)
if created:
executor.submit(get_created_issues)

return list(set(issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
Expand Down

0 comments on commit 71c5775

Please sign in to comment.