<commit_before>from django.utils.translation import ugettext as _

from kuma.wiki.feeds import DocumentsFeed

from .models import AttachmentRevision


class AttachmentsFeed(DocumentsFeed):
    title = _("MDN recent file changes")
    subtitle = _("Recent revisions to MDN file attachments")

    def items(self):
        return AttachmentRevision.objects.order_by('-created')[:50]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        if item.get_previous() is None:
            return '<p>Created by: %s</p>' % item.creator.username
        return "<p>Edited by %s: %s" % (item.creator.username, item.comment)

    def item_link(self, item):
        return self.request.build_absolute_uri(
            item.attachment.get_absolute_url())

    def item_pubdate(self, item):
        return item.created

    def item_author_name(self, item):
        return '%s' % item.creator

    def item_author_link(self, item):
        return self.request.build_absolute_uri(item.creator.get_absolute_url())

    def item_categories(self, item):
        return []<commit_msg>Bug 1183082 - Improve performance of attachment feeds.<commit_after>from django.utils.translation import ugettext as _

from kuma.wiki.feeds import DocumentsFeed

from .models import AttachmentRevision


class AttachmentsFeed(DocumentsFeed):
    title = _("MDN recent file changes")
    subtitle = _("Recent revisions to MDN file attachments")

    def items(self):
        return (AttachmentRevision.objects.prefetch_related('creator',
                                                            'attachment')
                                          .order_by('-created')[:50])

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        if item.get_previous() is None:
            return '<p>Created by: %s</p>' % item.creator.username
        else:
            return '<p>Edited by %s: %s' % (item.creator.username,
                                            item.comment)

    def item_link(self, item):
        return self.request.build_absolute_uri(
            item.attachment.get_absolute_url())

    def item_pubdate(self, item):
        return item.created

    def item_author_name(self, item):
        return item.creator.username

    def item_author_link(self, item):
        return self.request.build_absolute_uri(item.creator.get_absolute_url())

    def item_categories(self, item):
        return []
{'fraction_non_alphanumeric': 0.09838709677419355, 'fraction_numerical': 0.004435483870967742, 'mean_word_length': 2.58008658008658, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2851530', 'n_tokens_mistral': 721, 'n_tokens_neox': 677, 'n_words': 170}