<commit_before>from __future__ import absolute_import, division, unicode_literals

import itertools

from sqlalchemy.orm import joinedload

from changes.api.base import APIView
from changes.constants import Status
from changes.models import Build, Project, Revision, Source


class ProjectCommitIndexAPIView(APIView):
    def get(self, project_id):
        project = Project.get(project_id)
        if not project:
            return '', 404

        repo = project.repository
        vcs = repo.get_vcs()

        if vcs:
            vcs_log = list(vcs.log())

            revisions_qs = list(Revision.query.options(
                joinedload('author'),
            ).filter(
                Revision.repository_id == repo.id,
                Revision.sha.in_(c.id for c in vcs_log)
            ))

            revisions_map = dict(
                (c.sha, d)
                for c, d in itertools.izip(revisions_qs, self.serialize(revisions_qs))
            )

            commits = []
            for commit in vcs_log:
                if commit.id in revisions_map:
                    result = revisions_map[commit.id]
                else:
                    result = self.serialize(commit)
                commits.append(result)
        else:
            commits = self.serialize(list(
                Revision.query.options(
                    joinedload('author'),
                ).filter(
                    Revision.repository_id == repo.id,
                ).order_by(Revision.date_created.desc())[:100]
            ))

        builds_qs = list(Build.query.options(
            joinedload('author'),
            joinedload('source'),
        ).filter(
            Build.source_id == Source.id,
            Build.project_id == project.id,
            Build.status.in_([Status.finished, Status.in_progress, Status.queued]),
            Source.revision_sha.in_(c['id'] for c in commits),
            Source.patch == None,  # NOQA
        ).order_by(Build.date_created.asc()))

        builds_map = dict(
            (b.source.revision_sha, d)
            for b, d in itertools.izip(builds_qs, self.serialize(builds_qs))
        )

        results = []
        for result in commits:
            result['build'] = builds_map.get(result['id'])
            results.append(result)

        context = {
            'commits': results,
        }

        return self.respond(context)
<commit_msg>Dont call in_ with empty clause<commit_after>from __future__ import absolute_import, division, unicode_literals

import itertools

from sqlalchemy.orm import joinedload

from changes.api.base import APIView
from changes.constants import Status
from changes.models import Build, Project, Revision, Source


class ProjectCommitIndexAPIView(APIView):
    def get(self, project_id):
        project = Project.get(project_id)
        if not project:
            return '', 404

        repo = project.repository
        vcs = repo.get_vcs()

        if vcs:
            vcs_log = list(vcs.log())

            if vcs_log:
                revisions_qs = list(Revision.query.options(
                    joinedload('author'),
                ).filter(
                    Revision.repository_id == repo.id,
                    Revision.sha.in_(c.id for c in vcs_log)
                ))

                revisions_map = dict(
                    (c.sha, d)
                    for c, d in itertools.izip(revisions_qs, self.serialize(revisions_qs))
                )

                commits = []
                for commit in vcs_log:
                    if commit.id in revisions_map:
                        result = revisions_map[commit.id]
                    else:
                        result = self.serialize(commit)
                    commits.append(result)
            else:
                commits = []
        else:
            commits = self.serialize(list(
                Revision.query.options(
                    joinedload('author'),
                ).filter(
                    Revision.repository_id == repo.id,
                ).order_by(Revision.date_created.desc())[:100]
            ))

        builds_qs = list(Build.query.options(
            joinedload('author'),
            joinedload('source'),
        ).filter(
            Build.source_id == Source.id,
            Build.project_id == project.id,
            Build.status.in_([Status.finished, Status.in_progress, Status.queued]),
            Source.revision_sha.in_(c['id'] for c in commits),
            Source.patch == None,  # NOQA
        ).order_by(Build.date_created.asc()))

        builds_map = dict(
            (b.source.revision_sha, d)
            for b, d in itertools.izip(builds_qs, self.serialize(builds_qs))
        )

        results = []
        for result in commits:
            result['build'] = builds_map.get(result['id'])
            results.append(result)

        context = {
            'commits': results,
        }

        return self.respond(context)

{'fraction_non_alphanumeric': 0.09808660624370594, 'fraction_numerical': 0.002416918429003021, 'mean_word_length': 1.5757261410788381, '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': '7230372', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1323, 'n_words': 281}