Fix three N+1 queries in pin loading

Fetch the submitter with a join and get all the images and tags in one
query each. This reduces the total query count for loading 50 pins from
304 to 158.

See issue #85.
This commit is contained in:
Jens Gutermuth
2015-03-23 01:58:12 +01:00
parent 613db5c505
commit 60cf2dcbd7

View File

@@ -135,7 +135,8 @@ class PinResource(ModelResource):
filtering = { filtering = {
'submitter': ALL_WITH_RELATIONS 'submitter': ALL_WITH_RELATIONS
} }
queryset = Pin.objects.all() queryset = Pin.objects.all().select_related('submitter'). \
prefetch_related('image', 'tags')
resource_name = 'pin' resource_name = 'pin'
include_resource_uri = False include_resource_uri = False
always_return_data = True always_return_data = True