<commit_before>from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
from django.utils.translation import ugettext as _
from django.views.generic.detail import DetailView

from packages.models import Release


class ReleaseDetail(DetailView):

    model = Release
    queryset = Release.objects.filter(deleted=False, package__deleted=False)

    def get_context_data(self, **kwargs):
        ctx = super(ReleaseDetail, self).get_context_data(**kwargs)
        ctx.update({
            "version_specific": self.kwargs.get("version", None),
        })
        return ctx

    def get_object(self, queryset=None):
        if queryset is None:
            queryset = self.get_queryset()

        package = self.kwargs["package"]
        version = self.kwargs.get("version", None)

        queryset = queryset.filter(package__name=package)

        if version:<commit_msg>use prefetch related to reduce query overhead<commit_after>from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
from django.utils.translation import ugettext as _
from django.views.generic.detail import DetailView

from packages.models import Release


class ReleaseDetail(DetailView):

    model = Release
    queryset = Release.objects.filter(
                    deleted=False,
                    package__deleted=False
                ).prefetch_related(
                    "uris",
                    "files",
                    "requires",
                    "provides",
                    "obsoletes",
                    "classifiers",
                )

    def get_context_data(self, **kwargs):
        ctx = super(ReleaseDetail, self).get_context_data(**kwargs)
        ctx.update({
            "version_specific": self.kwargs.get("version", None),
        })
        return ctx

    def get_object(self, queryset=None):
        if queryset is None:
            queryset = self.get_queryset()

        package = self.kwargs["package"]
        version = self.kwargs.get("version", None)

        queryset = queryset.filter(package__name=package)

        if version:
{'fraction_non_alphanumeric': 0.09039280643634642, 'fraction_numerical': 0.002839564600094652, 'mean_word_length': 2.393258426966292, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2539063', 'n_tokens_mistral': 569, 'n_tokens_neox': 540, 'n_words': 129}