Reduces the number of DB queries performed for GET apiv2beta/dweets from ~44 to 8
This PR does the following:
Adds related_name=remixes to the reply_to field in the Dweet model. This was done to make it more intuitive to read code that uses the reverse relation.
(Note: When writing this I realize there's an inconsistency between the terminology of dweet "replies" and "remixes" in the code. Maybe we should rename the reply_to field remix_of later to make it even clearer?)
Removes the awesome_count field from the remix-linked dweet. This was not used and generated an extra query for each dweet.
Changed awesome_count and has_user_awesomed from serializer methods to fields generated by annotation. Previously these two functions added 3 queries for each dweet.
prefetch_related for remixes, the original N+1 problem that led me down this path.
Added a prefetch_related for reply_to including prefetch of the related author user profile. Before I did that I saw a lot of extra user queries
When opening your Pull Request, we encourage you to do the following (you can add an X to check each task):
[x] Run make lint to ensure that all the files are formatted and using best practices.
Reduces the number of DB queries performed for
GET apiv2beta/dweets
from ~44 to 8This PR does the following:
related_name=remixes
to thereply_to
field in the Dweet model. This was done to make it more intuitive to read code that uses the reverse relation.reply_to
fieldremix_of
later to make it even clearer?)prefetch_related
forremixes
, the original N+1 problem that led me down this path.prefetch_related
forreply_to
including prefetch of the related author user profile. Before I did that I saw a lot of extra user queriesWhen opening your Pull Request, we encourage you to do the following (you can add an X to check each task):
make lint
to ensure that all the files are formatted and using best practices.