You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should check the database queries being generated for the Events end-point, and use .select_related and .prefetch_related to reduce any excess queries.
In general, to do query profiling:
Ensure Django Debug Toolbar is working, I just merged Django debug #682, we may need to test that it works under all local development scenarios.
Once Django Debug Toolbar is working, you can visit an API end-point like
Click on DjDT toolbar icon on the top-right of the page, and go to the Queries tab.
Inspecting the queries and SQL generated should give you a good idea if any of the related object lookups are being done in a loop instead of being fetched along-with the initial query.
To optimize, we'd add .select_related() and .prefetch_related calls to the ORM call in the get_queryset method for the view, and then one can re-inspect the queries in the Django Debug Toolbar to verify that the number of queries and overall query times have reduced.
Relates to #708
We should check the database queries being generated for the Events end-point, and use
.select_relatedand.prefetch_relatedto reduce any excess queries.In general, to do query profiling:
Queriestab.Inspecting the queries and SQL generated should give you a good idea if any of the related object lookups are being done in a loop instead of being fetched along-with the initial query.
To optimize, we'd add
.select_related()and.prefetch_relatedcalls to the ORM call in theget_querysetmethod for the view, and then one can re-inspect the queries in the Django Debug Toolbar to verify that the number of queries and overall query times have reduced.get_querysetmethod of the View: https://github.com/IFRCGo/go-api/blob/develop/api/drf_views.py#L251Django docs: https://docs.djangoproject.com/en/3.0/ref/models/querysets/#select-related