From patchwork Wed Jan 29 19:01:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mete Polat X-Patchwork-Id: 1231062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 487CYd5D1Nz9sQp for ; Thu, 30 Jan 2020 06:03:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Dg7CZYRO; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 487CYZ5QLrzDqSJ for ; Thu, 30 Jan 2020 06:03:14 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::443; helo=mail-wr1-x443.google.com; envelope-from=metepolat2000@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Dg7CZYRO; dkim-atps=neutral Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 487CX04rpszDqSH for ; Thu, 30 Jan 2020 06:01:52 +1100 (AEDT) Received: by mail-wr1-x443.google.com with SMTP id y17so765478wrh.5 for ; Wed, 29 Jan 2020 11:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3ZsxPvWkxhfSllWUlR30lfR5B9Ma6lXzLAwDuFpkpwo=; b=Dg7CZYROGgYb3ML38Fnbm9gaRsqza6xPR2UkokHVdVwiEPWBuItOwonoXzyVn3bTMW +9tW3PCfyvnR9iwMLfYo+rfQQNO0YfOkIPAYnIqxypqRg5fIXz75DIW6KtoMZw3VSPNK UIHp7Xai9vIyWlUH/sAmNkkW9Lwb0IIKkjesjKoqAwhW9a7NBoRTuwBHpDFwSz4GuytQ h3V+Ivn3f9UtcJLVqF3u8zmkuDWuc0x6ySU0kABP8sxNxtU2JW2J/YKCjNkPJ0qBIAOL vIuhVWFaMgfRqBkU7Bm7Uy0aTgybOqL7MIzG71wHuhYKwuLyLF79a6DaUx8R4ZY18VLl jUJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3ZsxPvWkxhfSllWUlR30lfR5B9Ma6lXzLAwDuFpkpwo=; b=dHpjnZdTDFjze8N9uuDVbbxEa7JjsS6RwwHviEKOABMYKT0oBTAfV9QbpalxM9UgW0 n/Zgjj+MWw/P4rYbW3dzPfaz5D1N2Akfvp19mglYk0zGEP+ZbSuCCDP4WBwspQqYQog6 F3XzFnWhruyN91L9k3+AIpoGCLziKyBtRZhIH8ZoPaFTYIufN7UwV4ZQaZSn1xUSn8b+ 5vwCmUhYTHjkDOfBcnF4o5K5fpXfvB6WlGhcBzFwnSzawiCrHfNXUELa1STyIgu6mwgm EL6JH4lZPJ0h2jaGTu1zgK9O7Ia0hbBswi1l9XfJK2gib0INPsFlXwX2kgBhXAfV2Np1 5hmQ== X-Gm-Message-State: APjAAAUsZMeZyjWXlcPpnTle/UfZnRU3C8ACGoVxc6ochhNq8I3PLSzO BW0u30tUW0cWkmIvFIQ0VEpM+Ckv X-Google-Smtp-Source: APXvYqyEl0pPrrQdAriOcyaMnR03aMBiRycwPzX6mJUt87OVV5OsQJwQftzT8gg8qI/gxl3oe3vDrw== X-Received: by 2002:adf:dcc2:: with SMTP id x2mr299074wrm.24.1580324506901; Wed, 29 Jan 2020 11:01:46 -0800 (PST) Received: from Metes-MBP.fritz.box (aftr-62-216-209-100.dynamic.mnet-online.de. [62.216.209.100]) by smtp.gmail.com with ESMTPSA id e17sm3156653wma.12.2020.01.29.11.01.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jan 2020 11:01:46 -0800 (PST) From: Mete Polat To: patchwork@lists.ozlabs.org Subject: [PATCH] REST: Fix duplicate project queries Date: Wed, 29 Jan 2020 20:01:22 +0100 Message-Id: <20200129190122.21264-1-metepolat2000@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Eliminates duplicate project queries caused by calling get_absolute_url() in the embedded serializers. Following foreign keys with 'series__project' will cache the project of the series as well as the series itself. Signed-off-by: Mete Polat --- There are still some duplicates in various /api/ views but it looks like those are caused by the REST framework itself. patchwork/api/cover.py | 2 +- patchwork/api/event.py | 4 ++-- patchwork/api/patch.py | 2 +- patchwork/api/series.py | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py index caf9a386efa5..9e86d47e00e5 100644 --- a/patchwork/api/cover.py +++ b/patchwork/api/cover.py @@ -101,7 +101,7 @@ class CoverLetterList(ListAPIView): def get_queryset(self): return CoverLetter.objects.all()\ - .select_related('project', 'submitter', 'series')\ + .select_related('project', 'submitter', 'series__project')\ .defer('content', 'headers') diff --git a/patchwork/api/event.py b/patchwork/api/event.py index a066faaec63b..fdff6a4f2fa6 100644 --- a/patchwork/api/event.py +++ b/patchwork/api/event.py @@ -86,7 +86,7 @@ class EventList(ListAPIView): def get_queryset(self): return Event.objects.all()\ - .prefetch_related('project', 'patch', 'series', 'cover', - 'previous_state', 'current_state', + .prefetch_related('project', 'patch__project', 'series__project', + 'cover', 'previous_state', 'current_state', 'previous_delegate', 'current_delegate', 'created_check') diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index a29a1ab0eb71..1a3ce9057490 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -176,7 +176,7 @@ class PatchList(ListAPIView): return Patch.objects.all()\ .prefetch_related('check_set')\ .select_related('project', 'state', 'submitter', 'delegate', - 'series')\ + 'series__project')\ .defer('content', 'diff', 'headers') diff --git a/patchwork/api/series.py b/patchwork/api/series.py index f7bb8c06a6c9..df28f95dab1b 100644 --- a/patchwork/api/series.py +++ b/patchwork/api/series.py @@ -55,8 +55,9 @@ class SeriesMixin(object): serializer_class = SeriesSerializer def get_queryset(self): - return Series.objects.all().prefetch_related('patches',)\ - .select_related('submitter', 'cover_letter', 'project') + return Series.objects.all()\ + .prefetch_related('patches__project',)\ + .select_related('submitter', 'cover_letter__project', 'project') class SeriesList(SeriesMixin, ListAPIView):