[PATCH] views: Use select_related, not prefetch_related

Daniel Axtens dja at axtens.net
Wed Oct 31 00:47:44 AEDT 2018


Daniel Axtens <dja at axtens.net> writes:

> 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!
Much to my shame this breaks pep8 and I forgot to check before applying.

I have applied the following fixup:

commit ee20fdea757e393f5951aaf640331176fc6cb807 (HEAD, upstream-push/master)
Author: Daniel Axtens <dja at axtens.net>
Date:   Wed Oct 31 00:45:44 2018 +1100

    views: no longer import Series in __init__.py
    
    Fix a pep8 error due to an unused import.
    
    Fixes: 780b1a2d07ad ("views: Use select_related, not prefetch_related")
    Signed-off-by: Daniel Axtens <dja at axtens.net>

diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index cea614862d1e..6ec53ddacbe9 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -14,7 +14,6 @@ from patchwork.models import BundlePatch
 from patchwork.models import Patch
 from patchwork.models import Project
 from patchwork.models import Check
-from patchwork.models import Series
 from patchwork.paginator import Paginator
 
 


>> 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