From nobody Fri Apr 26 06:08:44 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 1525275009790416.25223956539605; Wed, 2 May 2018 08:30:09 -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 1CC12315002E; Wed, 2 May 2018 15:30:09 +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 0C9E330012B0; Wed, 2 May 2018 15:30:09 +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 01085180610F; Wed, 2 May 2018 15:30:08 +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 w42FRqi5007975 for ; Wed, 2 May 2018 11:27:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1ED922024CA9; Wed, 2 May 2018 15:27:52 +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 A3D772024CA8 for ; Wed, 2 May 2018 15:27:51 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 2 May 2018 17:27:50 +0200 Message-Id: <20180502152750.1224-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] cut number of queries for anonymous browsing 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.46]); Wed, 02 May 2018 15:30:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For a single request to http://127.0.0.1:8000/QEMU/ we get 78 SQL queries, and 50 of them are checking whether the project is maintained by the current logged in user. Certainly caching the answer is a possibility, but really an anonymous user is never going to be a maintainer. Adding the check to maintained_by cuts the queries from 78 to 28 and the processing time from 12 to 7 ms. Signed-off-by: Paolo Bonzini --- api/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/models.py b/api/models.py index 4cc2b74..504f2c7 100644 --- a/api/models.py +++ b/api/models.py @@ -131,6 +131,8 @@ class Project(models.Model): return Message.objects.series_heads(project=3Dself.name).count() =20 def maintained_by(self, user): + if user.is_anonymous: + return False if user.is_superuser: return True if self.maintainers.filter(id=3Duser.id).exists(): --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel