From ae661f8001d8a512b1b13c48ebe16747d98e8303 Mon Sep 17 00:00:00 2001 From: andrepapoti Date: Mon, 18 Mar 2024 14:42:29 -0300 Subject: [PATCH] serializers: Optimize query performance on SeriesMixin for 'related_series' Ensure the retrival of series is keept at O(1) complexity. Closes #506 Signed-off-by: andrepapoti --- patchwork/api/series.py | 6 +++++- patchwork/tests/api/test_series.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/patchwork/api/series.py b/patchwork/api/series.py index ab44ee70..0c22b3c1 100644 --- a/patchwork/api/series.py +++ b/patchwork/api/series.py @@ -98,7 +98,11 @@ class SeriesMixin(object): def get_queryset(self): return ( Series.objects.all() - .prefetch_related('patches__project', 'cover_letter__project') + .prefetch_related( + 'patches__project', + 'cover_letter__project', + 'related_series__project', + ) .select_related('submitter', 'project') ) diff --git a/patchwork/tests/api/test_series.py b/patchwork/tests/api/test_series.py index 730678a8..597b61a9 100644 --- a/patchwork/tests/api/test_series.py +++ b/patchwork/tests/api/test_series.py @@ -152,7 +152,7 @@ def test_list_bug_335(self): create_cover(series=series_obj) create_patch(series=series_obj) - with self.assertNumQueries(6): + with self.assertNumQueries(7): self.client.get(self.api_url()) @utils.store_samples('series-detail')