From nobody Tue May 13 15:34:52 2025 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; dkim=fail; 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 1538145951538355.7243006940927; Fri, 28 Sep 2018 07:45:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E39E43A35; Fri, 28 Sep 2018 14:45:50 +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 4DA2C5D73F; Fri, 28 Sep 2018 14:45:50 +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 3D2AD18005CD; Fri, 28 Sep 2018 14:45:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEjn6O024575 for ; Fri, 28 Sep 2018 10:45:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8471A2A342; Fri, 28 Sep 2018 14:45:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B8DD5DD87 for ; Fri, 28 Sep 2018 14:45:47 +0000 (UTC) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB2F730821F4 for ; Fri, 28 Sep 2018 14:45:45 +0000 (UTC) Received: by mail-wm1-f52.google.com with SMTP id s12-v6so2512570wmc.0 for ; Fri, 28 Sep 2018 07:45:45 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id n68-v6sm1884636wmn.5.2018.09.28.07.45.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=Zs3sHFzMyG7kPNixg4dIVXRRNOSg9uOYr5O8JNOH4/s=; b=oRjhJvdBCUWClHhyLXGhQqH+din2QK/vuWuWX3l0gpZN1LtVDnJ6wt69pxRXLGk0YE 2mI9hs2GYtG+csOI5TUDjS/3zhj2aKlZHqg1u/u3WDPMXI49sYKJc22mj3lxaH+5th37 Qjz3b+9xMjYNK+nYzg/7TFYYemIe+xHKhxfgGxAwggo0zvwRpaPFbY5CtrQsyvYVeq7g CHhYXinUsX9AphFlOFdVInCkuQPOwZZ7wW8KgSPFomQeicYy+8fllmlavg0ZybHVHrvA ZohdF3GpiN9P0bVVHNw/jnU+PRA4l1Sx4CwbQvcRp7U4FcpZBT+CtgqNN4YAUxlXpJvQ zYJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=Zs3sHFzMyG7kPNixg4dIVXRRNOSg9uOYr5O8JNOH4/s=; b=sTO2/vYIBGkzEHIxZGPPOgkAUroRfndtYSyk54agbDW3z4pbMW6QFFl98dIpINbXRx uajUq94NVGeLXwcjuhzZVyRrgHlC8gaF/jwPly9jUuOfnUQwzPfMeJ5DubmSveDG/PiS Tqvdt5KATg75k1YtsSFc7sHbkz52LSZJNXdBy5CptJ/DIe7hKOhfT1jPeVufPMmurdeX fQL5CssGqgYaVeeaglBPiT4OsVsurq9mWE59tLSjKROjbaJMtOryxcTCqjlMi66PPu5r Ub6NmlQQmvBwAc9AO+ga3mnH6ekGgAFj0oaan/oCuWsxVcI3Tm8DExWX3Ttb/oaVJ8Vw q51g== X-Gm-Message-State: ABuFfogIlui5qAmfoaxW79qJcP5uj+JAWbc/W4rfmTTKhyX/ne0Zd9QJ 7DNpH8OE9CXaIYD+n7pWCAN1GJPS28A= X-Google-Smtp-Source: ACcGV60VSH3PFw/W2K+EQyxhbUuK6G6NrHPqOzal64H7ChbnTw2iOjcG5K+kaIQJvwXg4i1kt+WRdw== X-Received: by 2002:a1c:ac82:: with SMTP id v124-v6mr2078916wme.10.1538145944225; Fri, 28 Sep 2018 07:45:44 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:45:30 +0200 Message-Id: <20180928144537.5051-4-pbonzini@redhat.com> In-Reply-To: <20180928144537.5051-1-pbonzini@redhat.com> References: <20180928144537.5051-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 28 Sep 2018 14:45:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 28 Sep 2018 14:45:46 +0000 (UTC) for IP:'209.85.128.52' DOMAIN:'mail-wm1-f52.google.com' HELO:'mail-wm1-f52.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.488 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.128.52 mail-wm1-f52.google.com 209.85.128.52 mail-wm1-f52.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 03/10] search: introduce _make_filter_subquery 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Sep 2018 14:45:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Django is pretty inefficient when related fields are introduced, and sometimes incorrect results are produced (for example "success:testing -failure:testing" does not work if Results are queried through result__* fields). A more efficient (and working) way to achieve the same is to use "IN" with subqueries. Convert is:applied, is:tested and is:obsoleted/is:old to use subqueries. Signed-off-by: Paolo Bonzini --- api/search.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/api/search.py b/api/search.py index 17424c3..b33aa1b 100644 --- a/api/search.py +++ b/api/search.py @@ -8,7 +8,7 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -from .models import Message, Result +from .models import Message, MessageProperty, Result from django.db.models import Q =20 class InvalidSearchTerm(Exception): @@ -124,6 +124,10 @@ Search text keyword in the email message. Example: regression =20 """ + def _make_filter_subquery(self, model, q): + message_ids =3D model.objects.filter(q).values('message_id') + return Q(id__in=3Dmessage_ids) + def _process_term(self, query, term, neg=3DFalse): """ Return a Q object that will be applied to the query """ def as_keywords(t): @@ -163,19 +167,15 @@ Search text keyword in the email message. Example: elif cond =3D=3D "pull": q =3D Q(subject__contains=3D'[PULL') | Q(subject__contains= =3D'[GIT PULL') elif cond =3D=3D "reviewed": - q =3D Q(properties__name=3D"reviewed", - properties__value=3DTrue) + q =3D self._make_filter_subquery(MessageProperty, Q(name= =3D"reviewed", value=3DTrue)) elif cond in ("obsoleted", "old"): - q =3D Q(properties__name=3D"obsoleted-by", - properties__value__isnull=3DFalse) & \ - ~Q(properties__name=3D"obsoleted-by", - properties__value__iexact=3D'') + q =3D self._make_filter_subquery(MessageProperty, + Q(name=3D"obsoleted-by", va= lue__isnull=3DFalse) & + ~Q(name=3D"obsoleted-by", v= alue__iexact=3D'')) elif cond =3D=3D "applied": - q =3D Q(results__name=3D"git", - results__status=3DResult.SUCCESS) + q =3D self._make_filter_subquery(MessageResult, Q(name=3D"= git", status=3DResult.SUCCESS)) elif cond =3D=3D "tested": - q =3D Q(properties__name=3D"testing.done", - properties__value=3DTrue) + q =3D self._make_filter_subquery(MessageProperty, Q(name= =3D"testing.done", value=3DTrue)) elif cond =3D=3D "merged": q =3D Q(is_merged=3DTrue) else: --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel