-
Notifications
You must be signed in to change notification settings - Fork 331
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
Fix N+1 queries in /api/v1/patient/
#1337
Comments
i would like to work on this can you assign me this issue? |
Hey @satyam0601 |
hey, |
Hey @sainak @rithviknishad, I believe the primary issue with the hcx_policy query comes from https://github.com/coronasafe/care/blob/411e89c63c7daa4b13cc76a1754debec9c19bea7/care/facility/api/serializers/patient.py#L93 def get_has_eligible_policy(self, patient):
eligible_policies = Policy.objects.filter(
(Q(error_text="") | Q(error_text=None)),
outcome="complete",
patient=patient.id,
)
return bool(len(eligible_policies)) in the patient serializer. To address this, we can utilize prefetch_related and then filter the patient object with the necessary policy set. Additionally, I suggest replacing len with count, as both accomplish the same task. |
Sentry Issue: CARE-NF
The text was updated successfully, but these errors were encountered: