Skip to content

Conversation

jarekwg
Copy link
Contributor

@jarekwg jarekwg commented Aug 4, 2016

Some options to reduce the number of queries made when using relationships.

Currently the number of db queries made explodes out when either:

  • Including just the primary key as a field in a serializer, without actually "including" it
  • Actually "including" relationships

without prefetching on the viewset's queryset. For complicated models it can be very expensive to defensively prefetch everything every time, so these changes attempt to only fetch them from the db when needed.

  • Added dj110/drf34 tox tests.

Test all pass now, please merge. :)

bor3ham and others added 8 commits August 4, 2016 12:56
Rather than making another query to fetch the object for every result.
The validation here is awkward (following the relationships through
the model fields), I couldn't find a better way to ensure the
included args exist for a django prefetch rather than erroring out.
@jerel jerel merged commit 04a100c into django-json-api:develop Aug 9, 2016
@jarekwg jarekwg deleted the optimize/relationship-extraction branch October 19, 2018 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants