-
Notifications
You must be signed in to change notification settings - Fork 284
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 facility n+1 #2089
Fix facility n+1 #2089
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
"district", | ||
"state", | ||
) | ||
.prefetch_related("patientregistration_set", "bed_set") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of prefetch try annotating the count using subquery, and in the serializer check if the annotated attribute is present else fallback to filtering
return PatientRegistration.objects.filter( | ||
facility=facility, is_active=True | ||
).count() | ||
return facility.patientregistration_set.count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return facility.patientregistration_set.count() | |
if getattr(self, "annotated_count...": | |
return self.annotated_count... | |
return facility.patientregistration_set.filter(is_active=True).count() |
@sainak have resolved your comments pls take a look |
Closing this because we are considering an approach with redis based caching with existing design. |
Proposed Changes
using prefetch related for both the fields (PatientRegistration and Bed)
Associated Issue
fixes: #1920
Architecture changes
Merge Checklist
/docs
Only PR's with test cases included and passing lint and test pipelines will be reviewed
@coronasafe/care-backend-maintainers @coronasafe/care-backend-admins