[PATCH] views: Use select_related, not prefetch_related

Daniel Axtens dja at axtens.net
Wed Oct 31 00:20:46 AEDT 2018


Stephen Finucane <stephen at that.guru> writes:

> 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.
>
Tested-by: Daniel Axtens <dja at axtens.net>

And applied, thank you!
> 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
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork


More information about the Patchwork mailing list