瀏覽代碼

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.
pull/86/head
Jens Gutermuth 9 年之前
父節點
當前提交
60cf2dcbd7
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. +2
    -1
      pinry/core/api.py

+ 2
- 1
pinry/core/api.py 查看文件

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


Loading…
取消
儲存