[PATCH] views: Use select_related, not prefetch_related
Stephen Finucane
stephen at that.guru
Tue Oct 30 02:46:39 AEDT 2018
Now that there's a 1:N rather than N:M relationship between series and
patches, we should be using select_related rather than prefetch_related.
Signed-off-by: Stephen Finucane <stephen at that.guru>
Closes: #223
Fixes: 76505e91 ("models: Convert Series-Patch relationship to 1:N")
---
patchwork/views/__init__.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 178b3d41..cea61486 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -273,17 +273,16 @@ def generic_list(request, project, view, view_args=None, filter_settings=None,
# but we will need to follow the state and submitter relations for
# rendering the list template
- patches = patches.select_related('state', 'submitter', 'delegate')
+ patches = patches.select_related('state', 'submitter', 'delegate',
+ 'series')
patches = patches.only('state', 'submitter', 'delegate', 'project',
- 'name', 'date')
+ 'series__name', 'name', 'date')
# we also need checks and series
patches = patches.prefetch_related(
Prefetch('check_set', queryset=Check.objects.only(
'context', 'user_id', 'patch_id', 'state', 'date')))
- patches = patches.prefetch_related(
- Prefetch('series', queryset=Series.objects.only('name')))
paginator = Paginator(request, patches)
--
2.17.2
More information about the Patchwork
mailing list