Skip to content

Commit

Permalink
Merge pull request #353 from DmGorokhov/fix_bug/issue_315_fix_N+1
Browse files Browse the repository at this point in the history
Fix bug/issue 315 fix n+1
  • Loading branch information
sgmdlt authored Oct 13, 2023
2 parents a7f125b + 75d81df commit 8d453b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 13 additions & 3 deletions contributors/views/issues.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db.models import Prefetch
from django_filters.views import FilterView

from contributors.models import Contribution, ContributionLabel
Expand All @@ -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
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion contributors/views/pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)

0 comments on commit 8d453b3

Please sign in to comment.