Skip to content

Commit

Permalink
Feature/GSI for signature query
Browse files Browse the repository at this point in the history
- Added the project-reference index for searching signatures to improve performance

Signed-off-by: Harold Wanyama <[email protected]>
  • Loading branch information
nickmango committed Jan 18, 2024
1 parent ef96530 commit 5b6b9da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
40 changes: 31 additions & 9 deletions cla-backend/cla/models/dynamo_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ class Meta:
signature_company_signatory_id = UnicodeAttribute(hash_key=True)


class SignatureProjectReferenceIndex(GlobalSecondaryIndex):
"""
This class represents a global secondary index for querying signatures by project reference ID
"""

class Meta:
""" Meta class for Signature Project Reference Index """

index_name = "signature-project-reference-index"
write_capacity_units = 10
read_capacity_units = 10
projection = AllProjection()

signature_project_id = UnicodeAttribute(hash_key=True)
signature_reference_id = UnicodeAttribute(range_key=True)

class SignatureCompanyInitialManagerIndex(GlobalSecondaryIndex):
"""
This class represents a global secondary index for querying signatures by signature company initial manager ID
Expand Down Expand Up @@ -2431,7 +2447,7 @@ class Meta:
signature_project_id = UnicodeAttribute()
signature_document_minor_version = NumberAttribute()
signature_document_major_version = NumberAttribute()
signature_reference_id = UnicodeAttribute()
signature_reference_id = UnicodeAttribute(range_key=True)
signature_reference_name = UnicodeAttribute(null=True)
signature_reference_name_lower = UnicodeAttribute(null=True)
signature_reference_type = UnicodeAttribute()
Expand Down Expand Up @@ -2467,6 +2483,7 @@ class Meta:
signature_company_signatory_index = SignatureCompanySignatoryIndex()
signature_company_initial_manager_index = SignatureCompanyInitialManagerIndex()
project_signature_external_id_index = SignatureProjectExternalIndex()
signature_project_reference_index = SignatureProjectReferenceIndex()

# approval lists (previously called whitelists) are only used by CCLAs
domain_whitelist = ListAttribute(null=True)
Expand Down Expand Up @@ -2974,8 +2991,13 @@ def get_signatures_by_reference(

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))
cla.log.debug(f'{fn} - generator.last_evaluated_key: {signature_generator.last_evaluated_key}')
# signature_generator = self.model.signature_reference_index.query(str(reference_id))
try:
signature_generator = self.model.signature_project_reference_index.query(str(project_id), range_key_condition=SignatureModel.signature_reference_id == str(reference_id))
except Exception as e:
cla.log.error(f'{fn} - error performing signature_reference_id query using: {reference_id} - '
f'error: {e}')
raise e

signatures = []
for signature_model in signature_generator:
Expand All @@ -2999,12 +3021,12 @@ def get_signatures_by_reference(
f"versus {user_ccla_company_id}")
continue

# Skip signatures that are not of the same project
if project_id is not None and signature_model.signature_project_id != project_id:
cla.log.debug(f"{fn} - skipping signature - "
f"project_id values do not match: {signature_model.signature_project_id} "
f"versus {project_id}")
continue
# # Skip signatures that are not of the same project
# if project_id is not None and signature_model.signature_project_id != project_id:
# cla.log.debug(f"{fn} - skipping signature - "
# f"project_id values do not match: {signature_model.signature_project_id} "
# f"versus {project_id}")
# continue

# Skip signatures that do not have the same signed flags
# e.g. retrieving only signed / approved signatures
Expand Down
5 changes: 4 additions & 1 deletion cla-backend/cla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,10 @@ def user_signed_project_signature(user: User, project: Project) -> bool:
# Verify if user has been approved: https://github.com/communitybridge/easycla/issues/332
cla.log.debug(f'{fn} - CCLA signature check - '
'checking to see if the user is in one of the approval lists...')
if user.is_approved(signature):
if project.get_project_ccla_requires_icla_signature() is True:
cla.log.debug(f'{fn} - CCLA signature check - '
'project requires ICLA signature as well as CCLA signature ')
elif user.is_approved(signature) :
ccla_pass = True
else:
# Set user signatures approved = false due to user failing whitelist checks
Expand Down

0 comments on commit 5b6b9da

Please sign in to comment.