Reputation: 281
I'm trying to understand how many SQL select queries each request on my app requires (Django+Tastypie). I changed the logging configuration so I can see the relevant logs. For some reason I see a vast number of these logs. For example, for simple get_list - I see ~100 select lines. When I tried to debug, to see where they all come from, I couldn't step into the lines that generate these logs. I also noticed the numbers on the left are very low (usually 0.001). I assume that this number is time to perform the query (in sec).
Any idea what's the explanation for all these lines?
Upvotes: 2
Views: 405
Reputation: 894
In your tastypie api.py file you probably need to change the default queryset to either include prefetch_related or select_related. Which you use depends on your actual model. Here's an example:
class OfferResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user', full=False)
country = fields.ForeignKey(CountryResource, 'country', full=True)
campaign = fields.ForeignKey(CampaignResource, 'campaign', full=False)
network = fields.ForeignKey(NetworkResource, 'network', full=False, null=True)
class Meta:
queryset = Offer.objects.prefetch_related('offerstat').select_related('country', 'campaign', 'network').all()
Upvotes: 1