summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-05-07 20:24:17 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-05-08 11:05:39 +0800
commit2c2f5e99038e223a8baed9766779fc6dbc98137e (patch)
tree15e56e9abf068710a385a6347af7b895a5584f37
parent81a65cc81d151cbb412d2a833abab24dfc133a49 (diff)
downloadpatchwork-2c2f5e99038e223a8baed9766779fc6dbc98137e.tar.bz2
patchwork-2c2f5e99038e223a8baed9766779fc6dbc98137e.tar.xz
views/generic_list: reduce number of queries in list rendering
Currently, we do two database queries per patch on a list view; one to retrieve the submitter, and one for the state. This patch adds a .select_related to fetch for the submitter and state, and a .defer() to prevent loading large amounts of text data from the patch content and headers. This gives a significant reduction in the work per request. For a paginated list view (ie 100 patches per page): before after User 1344 ms 228 ms System 170 ms 25 ms Total 1514 ms 253 ms Elapsed 1605 ms 274 ms Context switch (vol) 4206 40 Context switch (invol) 326 75 SQL queries 212 15 Longest query 13 ms 5 ms Total query time 121 ms 20 ms Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--apps/patchwork/views/__init__.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/apps/patchwork/views/__init__.py b/apps/patchwork/views/__init__.py
index 4c63618..9d1d144 100644
--- a/apps/patchwork/views/__init__.py
+++ b/apps/patchwork/views/__init__.py
@@ -108,6 +108,14 @@ def generic_list(request, project, view,
if not editable_order:
patches = order.apply(patches)
+ # we don't need the content or headers for a list; they're text fields
+ # that can potentially contain a lot of data
+ patches = patches.defer('content', 'headers')
+
+ # but we will need to follow the state and submitter relations for
+ # rendering the list template
+ patches = patches.select_related('state', 'submitter')
+
paginator = Paginator(request, patches)
context.update({