[PATCH 3/5] Revert "Be sensible computing project patch counts"

Andrew Donnellan ajd at linux.ibm.com
Fri Mar 20 12:31:21 AEDT 2020


On 4/3/20 10:54 pm, Stephen Finucane wrote:
> This reverts commit cfcf2f2a80ac0709f1a5fd9aa212c8403daa5a18.
> 
> This will no longer be necessary once we remove the Patch-Submission
> split. Revert it now to avoid needing to rejig this later.
> 
> Conflicts:
> 	patchwork/views/project.py
> 
> NOTE(stephenfin): Conflicts are due to commit 880ec8c5 ("Fetch
> maintainer information in one query") which changed nearby lines.
> 
> Signed-off-by: Stephen Finucane <stephen at that.guru>
> Cc: Daniel Axtens <dja at axtens.net>

Looks fine

Reviewed-by: Andrew Donnellan <ajd at linux.ibm.com>

> ---
>   patchwork/views/project.py | 29 ++++-------------------------
>   1 file changed, 4 insertions(+), 25 deletions(-)
> 
> diff --git a/patchwork/views/project.py b/patchwork/views/project.py
> index 8fa41794..4c25f715 100644
> --- a/patchwork/views/project.py
> +++ b/patchwork/views/project.py
> @@ -10,10 +10,9 @@ from django.shortcuts import get_object_or_404
>   from django.shortcuts import render
>   from django.urls import reverse
>   
> +from patchwork.models import Patch
>   from patchwork.models import Project
>   
> -from django.db import connection
> -
>   
>   def project_list(request):
>       projects = Project.objects.all()
> @@ -31,34 +30,14 @@ def project_list(request):
>   
>   def project_detail(request, project_id):
>       project = get_object_or_404(Project, linkname=project_id)
> -
> -    # So, we revert to raw sql because if we do what you'd think would
> -    # be the correct thing in Django-ese, it ends up doing a *pointless*
> -    # join with patchwork_submissions that ends up ruining the query.
> -    # So, we do not do this, as this is wrong:
> -    #
> -    #   patches = Patch.objects.filter(
> -    #       patch_project_id=project.id).only('archived')
> -    #   patches = patches.annotate(c=Count('archived'))
> -    #
> -    # and instead do this, because it's simple and fast
> -
> -    n_patches = {}
> -    with connection.cursor() as cursor:
> -        cursor.execute('SELECT archived,COUNT(submission_ptr_id) as c '
> -                       'FROM patchwork_patch '
> -                       'WHERE patch_project_id=%s GROUP BY archived',
> -                       [project.id])
> -
> -        for r in cursor:
> -            n_patches[r[0]] = r[1]
> +    patches = Patch.objects.filter(project=project)
>   
>       context = {
>           'project': project,
>           'maintainers': User.objects.filter(
>               profile__maintainer_projects=project).select_related('profile'),
> -        'n_patches': n_patches[False] if False in n_patches else 0,
> -        'n_archived_patches': n_patches[True] if True in n_patches else 0,
> +        'n_patches': patches.filter(archived=False).count(),
> +        'n_archived_patches': patches.filter(archived=True).count(),
>           'enable_xmlrpc': settings.ENABLE_XMLRPC,
>       }
>       return render(request, 'patchwork/project.html', context)
> 

-- 
Andrew Donnellan              OzLabs, ADL Canberra
ajd at linux.ibm.com             IBM Australia Limited



More information about the Patchwork mailing list