From nobody Tue Apr 23 08:01:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525276804105779.0694146563109; Wed, 2 May 2018 09:00:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 868DE80484; Wed, 2 May 2018 16:00:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C70118514; Wed, 2 May 2018 16:00:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 49913180BAE6; Wed, 2 May 2018 16:00:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w42FuIfW011130 for ; Wed, 2 May 2018 11:56:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C15D2023228; Wed, 2 May 2018 15:56:18 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-186.ams2.redhat.com [10.36.116.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id B309C2023227 for ; Wed, 2 May 2018 15:56:17 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 2 May 2018 17:56:15 +0200 Message-Id: <20180502155616.3826-2-pbonzini@redhat.com> In-Reply-To: <20180502155616.3826-1-pbonzini@redhat.com> References: <20180502155616.3826-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/2] views: clean up add_msg_recurse X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 02 May 2018 16:00:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" prepare_message was being called twice for no reason. Probably just a cut-and-paste mistake. Signed-off-by: Paolo Bonzini --- www/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/views.py b/www/views.py index 6ecfe59..b01d37e 100644 --- a/www/views.py +++ b/www/views.py @@ -79,7 +79,7 @@ def prepare_series(request, s, skip_patches=3DFalse): def add_msg_recurse(m, skip_patches, depth=3D0): a =3D prepare_message(request, m, True) a.indent_level =3D min(depth, 4) - r.append(prepare_message(request, m, True)) + r.append(a) replies =3D m.get_replies() non_patches =3D [x for x in replies if not x.is_patch] patches =3D [] --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Tue Apr 23 08:01:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525276843196806.3051093896997; Wed, 2 May 2018 09:00:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A023632FE4E4; Wed, 2 May 2018 16:00:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9003430012B8; Wed, 2 May 2018 16:00:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7F340180BAE6; Wed, 2 May 2018 16:00:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w42FuIVP011135 for ; Wed, 2 May 2018 11:56:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id DD4E82023228; Wed, 2 May 2018 15:56:18 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-186.ams2.redhat.com [10.36.116.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71E132023227 for ; Wed, 2 May 2018 15:56:18 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 2 May 2018 17:56:16 +0200 Message-Id: <20180502155616.3826-3-pbonzini@redhat.com> In-Reply-To: <20180502155616.3826-1-pbonzini@redhat.com> References: <20180502155616.3826-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/2] cut number of queries for series detail view X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 02 May 2018 16:00:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The series detail views perform a lot of project queries to retrieve m.project.name. The project however is always known in advance; passing it directly to prepare_message as an argument is not the cleanest thing, but using prefetch_related/select_related does not fit Patchew's code very well: find_series_head already calls first() to retrieve a Message, and it is also ugly to sneak an annotate(project_name=3DF('project__name')) or select_related('project') in find_series_head. The full solution to avoid adding parameters like this one would probably involve class-based views, but for now this already cuts one query for each patch in the current series. --- www/views.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/www/views.py b/www/views.py index b01d37e..0361667 100644 --- a/www/views.py +++ b/www/views.py @@ -32,12 +32,12 @@ def render_page(request, template_name, **data): dispatch_module_hook("render_page_hook", context_data=3Ddata) return render(request, template_name, context=3Ddata) =20 -def prepare_message(request, m, detailed): +def prepare_message(request, project, m, detailed): name, addr =3D m.sender m.sender_full_name =3D "%s <%s>" % (name, addr) m.sender_display_name =3D name or addr m.age =3D m.get_age() - m.url =3D "/%s/%s" % (m.project.name, m.message_id) + m.url =3D reverse("series_detail", kwargs=3D{"project": project.name, = "message_id": m.message_id}) m.status_tags =3D [] if m.is_series_head: m.num_patches =3D m.get_num_patches() @@ -71,13 +71,15 @@ def prepare_patches(request, m, max_depth=3DNone): replies =3D m.get_replies().filter(is_patch=3DTrue) commit_replies =3D api.models.Message.objects.filter(in_reply_to=3DOut= erRef('message_id')) replies =3D replies.annotate(has_replies=3DExists(commit_replies)) - return [prepare_message(request, x, True) + project =3D m.project + return [prepare_message(request, project, x, True) for x in replies] =20 def prepare_series(request, s, skip_patches=3DFalse): r =3D [] + project =3D s.project def add_msg_recurse(m, skip_patches, depth=3D0): - a =3D prepare_message(request, m, True) + a =3D prepare_message(request, project, m, True) a.indent_level =3D min(depth, 4) r.append(a) replies =3D m.get_replies() @@ -87,12 +89,11 @@ def prepare_series(request, s, skip_patches=3DFalse): patches =3D [x for x in replies if x.is_patch] for x in non_patches + patches: add_msg_recurse(x, False, depth+1) - return r add_msg_recurse(s, skip_patches) return r =20 def prepare_series_list(request, sl): - return [prepare_message(request, s, False) for s in sl] + return [prepare_message(request, s.project, s, False) for s in sl] =20 def prepare_projects(): return api.models.Project.objects.filter(parent_project=3DNone).order_= by('-display_order', 'name') @@ -241,7 +242,7 @@ def view_series_detail(request, project, message_id): nav_path =3D prepare_navigate_list("View series", ("series_list", {"project": project}, project)) search =3D "id:" + message_id - series =3D prepare_message(request, s, True) + series =3D prepare_message(request, s.project, s, True) is_cover_letter=3Dnot series.is_patch return render_page(request, 'series-detail.html', subject=3Ds.subject, @@ -267,7 +268,7 @@ def view_series_message(request, project, thread_id, me= ssage_id): ("series_list", {"project": project}, project), ("series_detail", {"project": project, "message_id": t= hread_id}, s.subject )) search =3D "id:" + thread_id - series =3D prepare_message(request, s, True) + series =3D prepare_message(request, s.project, s, True) return render_page(request, 'series-detail.html', subject=3Dm.subject, stripped_subject=3Ds.stripped_subject, --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel