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>
if not editable_order:
patches = order.apply(patches)
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({
paginator = Paginator(request, patches)
context.update({