-
Notifications
You must be signed in to change notification settings - Fork 330
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
Fixed N+1 query occurrence in the /api/v1/facility/ #2260
Conversation
Annotated the count of beds & patients in queryset Fixes ohcnetwork#2256.
@gigincg Can you have a look at the PR? Thanks |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #2260 +/- ##
===========================================
+ Coverage 62.20% 63.50% +1.30%
===========================================
Files 221 238 +17
Lines 12204 13269 +1065
Branches 1742 1888 +146
===========================================
+ Hits 7591 8426 +835
- Misses 4305 4490 +185
- Partials 308 353 +45 ☔ View full report in Codecov by Sentry. |
@sainak Can you get this reviewed cc: @dhruv-goyal-10 |
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, can you add a test case for the list api to check the number of queries
like this:
https://github.com/coronasafe/care/blob/develop/care/facility/tests/test_bed_api.py#L38
|
@sainak Have a look at the PR now... |
bed_count=Count("bed"), | ||
patient_count=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.
Shouldn't we exclude related beds and patients that are deleted?
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.
cc: @sainak
Closing as new issue has been opened with a more appropriate solution: #2481 |
Changes Made
Annotated the count of beds & patients in Facility Queryset, which were causing N + 1 query problem.
Associated Issue
/api/v1/facility/
endpoint to improve performance and reduce database load. #2256Merge Checklist
/docs
@coronasafe/care-backend-maintainers @coronasafe/care-backend-admins