[09/11] Optimise fetching checks when displaying a patch

Message ID 20180810080106.10714-10-stewart@linux.ibm.com
State New
Headers show
Series
  • Performance for ALL THE THINGS!
Related show

Commit Message

Stewart Smith Aug. 10, 2018, 8:01 a.m.
Prior to this patch, a typical /patch// query for linuxppc-dev
(which has about half a dozen checks per patch) took around 20 queries
and 16.5ms in the database. About half of those queries were fetching
the checks and who did the check.

We can just do one query to get all that needed information, so we do
that. This brings a page load down to 10 queries in 12ms.

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
---
 patchwork/templates/patchwork/submission.html | 4 ++--
 patchwork/views/patch.py                      | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

Patch

diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html
index 3b6f9fbe909e..72bc947c3f2d 100644
--- a/patchwork/templates/patchwork/submission.html
+++ b/patchwork/templates/patchwork/submission.html
@@ -216,7 +216,7 @@  function toggle_div(link_id, headers_id)
  >{{ submission.pull_url }}</a>
 {% endif %}
 
-{% if submission.checks %}
+{% if checks %}
 <h2>Checks</h2>
 <table class="checks">
 <tr>
@@ -224,7 +224,7 @@  function toggle_div(link_id, headers_id)
   <th>Check</th>
   <th>Description</th>
 </tr>
-{% for check in submission.checks %}
+{% for check in checks %}
 <tr>
   <td>{{ check.user }}/{{ check.context }}</td>
   <td>
diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py
index e1d0cdcfcf39..fbde04280844 100644
--- a/patchwork/views/patch.py
+++ b/patchwork/views/patch.py
@@ -119,6 +119,7 @@  def patch_detail(request, patch_id):
     comments = comments.only('submitter','date','id','content','submission')
 
     context['all_series'] = patch.series.all().order_by('-date')
+    context['checks'] = patch.check_set.all().select_related('user')
     context['comments'] = comments
     context['submission'] = patch
     context['patchform'] = form