diff --git a/contributors/views/issues.py b/contributors/views/issues.py index af660db0..a115ccfb 100644 --- a/contributors/views/issues.py +++ b/contributors/views/issues.py @@ -1,3 +1,4 @@ +from django.db.models import Prefetch from django_filters.views import FilterView from contributors.models import Contribution, ContributionLabel @@ -15,9 +16,6 @@ class ListView( ): """A list of opened issues.""" - queryset = Contribution.objects.filter( - type='iss', info__state='open', - ).distinct() template_name = 'open_issues.html' filterset_class = IssuesFilter sortable_fields = ( # noqa: WPS317 @@ -35,6 +33,18 @@ class ListView( ) ordering = sortable_fields[0] + contributionlabel_prefetch = Prefetch( + 'labels', + queryset=ContributionLabel.objects.all(), + ) + + queryset = ( + Contribution.objects.filter(type='iss', info__state='open'). + select_related('repository', 'contributor', 'info'). + prefetch_related("repository__labels", contributionlabel_prefetch). + distinct() + ) + def get_context_data(self, *args, **kwargs): """Add context.""" all_contribution_id = Contribution.objects.filter( diff --git a/contributors/views/pull_requests.py b/contributors/views/pull_requests.py index c19408cb..206a9044 100644 --- a/contributors/views/pull_requests.py +++ b/contributors/views/pull_requests.py @@ -23,4 +23,7 @@ class ListView(TableSortSearchAndPaginationMixin, generic.ListView): ordering = sortable_fields[0] template_name = 'pull_requests_list.html' - queryset = Contribution.objects.filter(type='pr') + queryset = ( + Contribution.objects.filter(type='pr'). + select_related('repository', 'contributor', 'info') + )