<commit_before>from __future__ import absolute_import, division, unicode_literals

from flask import session
from sqlalchemy.orm import joinedload

from changes.api.base import APIView
from changes.models import Author, Build


class AuthorBuildIndexAPIView(APIView):
    def _get_author(self, author_id):
        if author_id == 'me':
            if not session.get('email'):
                return
            return Author.query.filter_by(email=session['email']).first()
        return Author.query.get(author_id)

    def get(self, author_id):
        author = self._get_author(author_id)
        if not author:
            return self.respond({
                'builds': [],
            })

        queryset = Build.query.options(
            joinedload(Build.project),
            joinedload(Build.author),
        ).filter(
            Build.author_id == author.id,
        ).order_by(Build.date_created.desc(), Build.date_started.desc())

        return self.paginate(queryset)
<commit_msg>Handle missing author<commit_after>from __future__ import absolute_import, division, unicode_literals

from flask import session
from sqlalchemy.orm import joinedload

from changes.api.base import APIView
from changes.models import Author, Build


class AuthorBuildIndexAPIView(APIView):
    def _get_author(self, author_id):
        if author_id == 'me':
            if not session.get('email'):
                return
            return Author.query.filter_by(email=session['email']).first()
        return Author.query.get(author_id)

    def get(self, author_id):
        author = self._get_author(author_id)
        if not author:
            return self.respond([])

        queryset = Build.query.options(
            joinedload(Build.project),
            joinedload(Build.author),
        ).filter(
            Build.author_id == author.id,
        ).order_by(Build.date_created.desc(), Build.date_started.desc())

        return self.paginate(queryset)

{'fraction_non_alphanumeric': 0.09892911779704233, 'fraction_numerical': 0.0, 'mean_word_length': 2.5934065934065935, 'pattern_counts': {'":': 0, '<': 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': '6253930', 'n_tokens_mistral': 553, 'n_tokens_neox': 537, 'n_words': 123}