care icon indicating copy to clipboard operation
care copied to clipboard

Fixed N+1 queries issue in /api/v1/consultationbed/

Open dhruv-goyal-10 opened this issue 1 year ago • 8 comments

Proposed Changes

  • The related fields of Bed like "bed__facility", "bed__location", "bed__location__facility" were causing the N + 1 queries issue, hence added them in select_related.

  • The related fields of prefetched_model asset was also causing the N + 1 queries issue, hence added the related fields of it in select_related, while using Prefetch() object.

  • To solve the N + 1 query issue related to is_occupied property of Bed Model, I have made necessary changes in PatientConsultationSerializer, to set the _is_occupied property of Bed instance, whose value is equal to the is_occupied property of Bed Model.

Associated Issue

  • Fixes #1339

Merge Checklist

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

Only PR's with test cases included and passing lint and test pipelines will be reviewed

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

dhruv-goyal-10 avatar Feb 23 '24 03:02 dhruv-goyal-10