From patchwork Thu Aug 9 03:59:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Smith X-Patchwork-Id: 955321 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41mDzL2dMtz9s1c for ; Thu, 9 Aug 2018 13:59:42 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41mDzL14wnzDr5t for ; Thu, 9 Aug 2018 13:59:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=stewart@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41mDzD5qMLzDqBy for ; Thu, 9 Aug 2018 13:59:36 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w793sMXN015995 for ; Wed, 8 Aug 2018 23:59:34 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kr99e136w-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 08 Aug 2018 23:59:33 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 8 Aug 2018 21:59:33 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 8 Aug 2018 21:59:31 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w793xUsK3473902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 8 Aug 2018 20:59:30 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 33C95BE051 for ; Wed, 8 Aug 2018 21:59:30 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E9C0EBE04F for ; Wed, 8 Aug 2018 21:59:29 -0600 (MDT) Received: from birb.localdomain (unknown [9.185.142.88]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP for ; Wed, 8 Aug 2018 21:59:29 -0600 (MDT) Received: by birb.localdomain (Postfix, from userid 1000) id EABEE4EC647; Thu, 9 Aug 2018 13:59:25 +1000 (AEST) From: Stewart Smith To: patchwork@lists.ozlabs.org Subject: [PATCH] 4x performance improvement for viewing patch with many comments Date: Thu, 9 Aug 2018 13:59:25 +1000 X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 x-cbid: 18080903-8235-0000-0000-00000DE4D424 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009510; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01071169; UDB=6.00551525; IPR=6.00850776; MB=3.00022599; MTD=3.00000008; XFM=3.00000015; UTC=2018-08-09 03:59:32 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080903-8236-0000-0000-00004234AB61 Message-Id: <20180809035925.15496-1-stewart@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-08-09_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=803 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808090041 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- patchwork/templates/patchwork/submission.html | 2 +- patchwork/views/cover.py | 5 +++++ patchwork/views/patch.py | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index e817713f7079..2f69735d6925 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -262,7 +262,7 @@ function toggle_div(link_id, headers_id) -{% for item in submission.comments.all %} +{% for item in comments %} {% if forloop.first %}

Comments

{% endif %} diff --git a/patchwork/views/cover.py b/patchwork/views/cover.py index 73f83cb99b99..edad90bc694d 100644 --- a/patchwork/views/cover.py +++ b/patchwork/views/cover.py @@ -45,6 +45,11 @@ 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_to_response('patchwork/submission.html', context) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index cbd4ec395d99..bbd84954726e 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -114,6 +114,11 @@ def patch_detail(request, patch_id): if is_authenticated(request.user): context['bundles'] = request.user.bundles.all() + comments = cover.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