Skip to content

Commit

Permalink
serializers: Optimize query performance on SeriesMixin for 'related_s…
Browse files Browse the repository at this point in the history
…eries'

Ensure the retrival of series is keept at O(1) complexity.

Closes getpatchwork#506

Signed-off-by: andrepapoti <[email protected]>
  • Loading branch information
andrepapoti committed Mar 19, 2024
1 parent 57fce40 commit ef87fb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion patchwork/api/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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')
)

Expand Down
2 changes: 1 addition & 1 deletion patchwork/tests/api/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ef87fb4

Please sign in to comment.