Skip to content

Commit

Permalink
Bug/Thread Pool commit
Browse files Browse the repository at this point in the history
- Used threading to handle commits

Signed-off-by: Harold Wanyama <[email protected]>
  • Loading branch information
nickmango committed Aug 4, 2023
1 parent cb91c66 commit daf6320
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
6 changes: 1 addition & 5 deletions cla-backend/cla/models/dynamo_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2969,16 +2969,12 @@ def get_signatures_by_reference(
):
fn = 'cla.models.dynamo_models.signature.get_signatures_by_reference'
cla.log.debug(f'{fn} - reference_id: {reference_id}, reference_type: {reference_type},'
f' project_id: {project_id}, user_ccla_company_id: {project_id},'
f' project_id: {project_id}, user_ccla_company_id: {user_ccla_company_id},'
f' signature_signed: {signature_signed}, signature_approved: {signature_approved}')

cla.log.debug(f'{fn} - performing signature_reference_id query using: {reference_id}')
# TODO: Optimize this query to use filters properly.
signature_generator = self.model.signature_reference_index.query(str(reference_id))
last_evaluated_key = signature_generator.last_evaluated_key
if last_evaluated_key is None:
cla.log.debug(f'{fn} - no last evaluated key found')
return []
cla.log.debug(f'{fn} - generator.last_evaluated_key: {signature_generator.last_evaluated_key}')

signatures = []
Expand Down
15 changes: 4 additions & 11 deletions cla-backend/cla/models/github_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def update_merge_group(self, installation_id, github_repository_id, merge_group_

try :
# Get Commit authors
commit_authors = get_pull_request_commit_authors(pull_request, installation_id)
commit_authors = get_pull_request_commit_authors(pull_request)
cla.log.debug(f'{fn} - commit authors: {commit_authors}')
except Exception as e:
cla.log.warning(f'{fn} - unable to load commit authors for PR {pull_request_id} from GitHub repository '
Expand Down Expand Up @@ -651,6 +651,9 @@ def update_change_request(self, installation_id, github_repository_id, change_re
# Get all unique users/authors involved in this PR - returns a List[UserCommitSummary] objects
commit_authors = get_pull_request_commit_authors(pull_request)

cla.log.debug(f'{fn} - PR: {pull_request.number}, found {len(commit_authors)} unique commit authors '
f'for pull request: {pull_request.number}')

try:
# Get existing repository info using the repository's external ID,
# which is the repository ID assigned by github.
Expand Down Expand Up @@ -1367,16 +1370,6 @@ def get_pull_request_commit_authors(pull_request) -> List[UserCommitSummary]:

commit_authors = []

# try:
# num_processes = multiprocessing.cpu_count()
# cla.log.debug(f'{fn} - Number of CPUs: {num_processes}')

# with multiprocessing.Pool(processes=num_processes) as pool:
# commit_authors = pool.starmap(get_author_summary, [(commit, pull_request.number) for commit in pull_request.get_commits()])

# except Exception as e:
# cla.log.warning(f'{fn} - Exception while querying pull request commits for author information: {e}')
# raise e
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
future_to_commit = {executor.submit(get_author_summary, commit, pull_request.number): commit for commit in pull_request.get_commits()}
for future in concurrent.futures.as_completed(future_to_commit):
Expand Down

0 comments on commit daf6320

Please sign in to comment.