Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[affiliation] Improve performance of affiliation jobs #836

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

sduenas
Copy link
Member

@sduenas sduenas commented Nov 30, 2023

The current algorithm was running unnecessary calls to 'find_individual_by_uuid' when the generic affiliation job was called. In other words, when the list of individuals to affiliate was all the individuals in the database.
To improve it, we have followed the same approach we did with the matching recommendations. We get the full list of individuals with a direct query using Django's API.

Comment on lines 175 to 179
try:
individual = find_individual_by_uuid(rec.key)
except NotFoundError:
logger.warning(f"Job {job.id} 'Individual {rec.key} not found'")
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this part. We have the individual.mk in rec.mk, and we can create the AffiliationRecommendation object using rec.mk, as we do in recommend_matches() with the following code:

try:
    with transaction.atomic():
        AffiliationRecommendation.objects.create(individual_id=rec.mk, organization=org)
except IntegrityError:
    pass

We can also use rec.key because recommend_affiliations() yields the same value for both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can only use rec.mk because if the list of uuids is not empty it will mean to create recommendations for those uuids only. In that case key is the uuid and not the mk

The current algorithm was running unnecessary
calls to 'find_individual_by_uuid' when the
generic affiliation job was called. In other words,
when the list of individuals to affiliate was
all the individuals in the database.

To improve it, we have followed the same approach
we did with the matching recommendations. We get
the full list of individuals with a direct query
using Django's API.

Signed-off-by: Santiago Dueñas <[email protected]>
@jjmerchante
Copy link
Contributor

LGTM

@jjmerchante jjmerchante merged commit c20e149 into chaoss:master Dec 12, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants