I am relatively new to django, and I am using select_related() and prefetch_related() in django to decrease my hits to the database.
this is a part of my views.py file:
topic = Topic.objects.filter(id=topic_id).select_related('followed_by')
questions = Question.objects.filter(topics=topic).prefetch_related('answers','question_comments','answers__created_by__userprofile','answers__answer_comments')
without the select_related and prefetch_related the view does 42 queries in 23.36MS, and with those added, it decreases to 10 queries in 7.91MS, looking at this data, I think those functions are really great.
So my question is this: Is there any downside to using these two functions? Should I not join this many tables in one go?