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

Fixed N+1 query occurrence in the /api/v1/facility/ #2260

Closed

Conversation

dhruv-goyal-10
Copy link
Contributor

@dhruv-goyal-10 dhruv-goyal-10 commented Jun 10, 2024

Changes Made

Annotated the count of beds & patients in Facility Queryset, which were causing N + 1 query problem.

Associated Issue

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

@coronasafe/care-backend-maintainers @coronasafe/care-backend-admins

Annotated the count of beds & patients in queryset

Fixes ohcnetwork#2256.
@dhruv-goyal-10 dhruv-goyal-10 requested a review from a team as a code owner June 10, 2024 17:18
@dhruv-goyal-10
Copy link
Contributor Author

@gigincg Can you have a look at the PR?

Thanks

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.50%. Comparing base (51ce81e) to head (c17b058).
Report is 125 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

@gigincg
Copy link
Member

gigincg commented Jun 14, 2024

@sainak Can you get this reviewed

cc: @dhruv-goyal-10

Copy link
Member

@sainak sainak left a 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

@gigincg
Copy link
Member

gigincg commented Jun 15, 2024

@dhruv-goyal-10

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

@dhruv-goyal-10
Copy link
Contributor Author

@sainak @gigincg I have added the test case for the same.

@dhruv-goyal-10
Copy link
Contributor Author

@sainak Have a look at the PR now...

@dhruv-goyal-10 dhruv-goyal-10 requested a review from sainak June 29, 2024 09:02
Comment on lines +79 to +80
bed_count=Count("bed"),
patient_count=Count(
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

cc: @sainak

@rithviknishad
Copy link
Member

rithviknishad commented Sep 22, 2024

Closing as new issue has been opened with a more appropriate solution: #2481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants