Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Prefetch related fields in API view's querysets #523

Closed
rmartz opened this issue Jun 23, 2017 · 2 comments · Fixed by #538
Closed

Prefetch related fields in API view's querysets #523

rmartz opened this issue Jun 23, 2017 · 2 comments · Fixed by #538

Comments

@rmartz
Copy link
Contributor

rmartz commented Jun 23, 2017

In the /city/ list view, we currently have a N+1 problem due to using the MapCell object as part of the serialization of City:
screen shot 2017-06-23 at 2 22 51 pm
The official solution for this appears to be to include the potentially needed related fields as part of the queryset for the parent view, so for CityViewSet we would change it to become

class CityViewSet(...):
    [...]
    queryset = City.objects.all().select_related('map_cell')

We should check if this problem exists for other views or API end points.

@CloudNiner
Copy link
Contributor

Great catch, thanks for writing up an issue!

@fungjj92
Copy link
Contributor

fungjj92 commented Jul 10, 2017

I didn't catch this on any other endpoint, but saw this false positive for indicator list:

screen shot 2017-07-10 at 2 40 34 pm

Because of the way historic date range is called in params init for appropriate indicators, the requests should in total be made as many times as there are related indicators (tho not ideal).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants