]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
4x performance improvement for viewing patch with many comments
authorStewart Smith <stewart@linux.ibm.com>
Fri, 10 Aug 2018 08:00:57 +0000 (18:00 +1000)
committerStephen Finucane <stephen@that.guru>
Fri, 31 Aug 2018 13:43:19 +0000 (14:43 +0100)
Using the example of id:20180720035941.6844-1-khandual@linux.vnet.ibm.com
with my test dataset of a chunk of a variety of mailing lists, has
this cover letter have 67 comments from a variety of people. Thus,
it's on the larger side of things.

Originally, displaying the /patch/550/ for this (redirected to /cover)
would take 81 SQL queries in ~60ms on my laptop.

After this optimisation, it's down to 14 queries in 14ms.

When the cache is cold, it's down to 32ms from 83ms.

The effect of this patch is to execute a join in the database to
get the submitter information for each comment at the same time as
getting all the comments rather than doing a one-by-one lookup after
the fact.

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
patchwork/templates/patchwork/submission.html
patchwork/views/cover.py
patchwork/views/patch.py

index e817713f7079c50233a384aacee371a102865c57..2f69735d69251cedf41f1ec1a0c27068ea0f53b4 100644 (file)
@@ -262,7 +262,7 @@ function toggle_div(link_id, headers_id)
 </pre>
 </div>
 
-{% for item in submission.comments.all %}
+{% for item in comments %}
 {% if forloop.first %}
 <h2>Comments</h2>
 {% endif %}
index aada6834aaa73b70cf0af14975d20045e00dd505..be5db2c215efaa3718d1a7019f475d8262f7833e 100644 (file)
@@ -45,6 +45,12 @@ def cover_detail(request, cover_id):
         'project': cover.project,
     }
 
+    comments = cover.comments.all()
+    comments = comments.select_related('submitter')
+    comments = comments.only('submitter', 'date', 'id', 'content',
+                             'submission')
+    context['comments'] = comments
+
     return render(request, 'patchwork/submission.html', context)
 
 
index 6921882e71d11ea664c01d0255f6d479e4635b8c..e000d0c6e739f0a5e2849dfeac38be8e1327cac0 100644 (file)
@@ -113,6 +113,12 @@ def patch_detail(request, patch_id):
     if request.user.is_authenticated:
         context['bundles'] = request.user.bundles.all()
 
+    comments = patch.comments.all()
+    comments = comments.select_related('submitter')
+    comments = comments.only('submitter', 'date', 'id', 'content',
+                             'submission')
+
+    context['comments'] = comments
     context['submission'] = patch
     context['patchform'] = form
     context['createbundleform'] = createbundleform