<commit_before>from flask import request, current_app
from marshmallow import fields
from sqlalchemy.orm import joinedload

from zeus.models import Repository, Revision
from zeus.utils.builds import fetch_builds_for_revisions

from .base_repository import BaseRepositoryResource
from ..schemas import BuildSchema, RevisionSchema


class RevisionWithBuildSchema(RevisionSchema):
    latest_build = fields.Nested(BuildSchema(), dump_only=True, required=False)


revisions_schema = RevisionWithBuildSchema(many=True, strict=True)


class RepositoryRevisionsResource(BaseRepositoryResource):
    def fetch_revisions(self, repo: Repository):
        if current_app.config.get('MOCK_REVISIONS'):
            return Revision.query \
                .filter(Revision.repository_id == repo.id) \
                .order_by(Revision.date_created.desc()) \
                .all()

        vcs = repo.get_vcs()
        if not vcs:
            return []

        vcs.ensure(update_if_exists=False)
        branch = request.args.get('branch', vcs.get_default_branch())
        parent = request.args.get('parent')

        vcs_log = list(vcs.log(
            limit=50,
            parent=parent,
            branch=branch,
        ))

        if not vcs_log:
            return []

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

        revisions_map = {r.sha: r for r in existing}<commit_msg>feat: Support per_page on revision list<commit_after>from flask import request, current_app
from marshmallow import fields
from sqlalchemy.orm import joinedload

from zeus.models import Repository, Revision
from zeus.utils.builds import fetch_builds_for_revisions

from .base_repository import BaseRepositoryResource
from ..schemas import BuildSchema, RevisionSchema


class RevisionWithBuildSchema(RevisionSchema):
    latest_build = fields.Nested(BuildSchema(), dump_only=True, required=False)


revisions_schema = RevisionWithBuildSchema(many=True, strict=True)


class RepositoryRevisionsResource(BaseRepositoryResource):
    def fetch_revisions(self, repo: Repository):
        if current_app.config.get('MOCK_REVISIONS'):
            return Revision.query \
                .filter(Revision.repository_id == repo.id) \
                .order_by(Revision.date_created.desc()) \
                .all()

        vcs = repo.get_vcs()
        if not vcs:
            return []

        vcs.ensure(update_if_exists=False)
        branch = request.args.get('branch', vcs.get_default_branch())
        parent = request.args.get('parent')

        vcs_log = list(vcs.log(
            limit=min(int(request.args.get('per_page', 50)), 50),
            parent=parent,
            branch=branch,
        ))

        if not vcs_log:
            return []

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

        revisions_map = {r.sha: r for r in existing}
{'fraction_non_alphanumeric': 0.09276729559748427, 'fraction_numerical': 0.0018867924528301887, 'mean_word_length': 2.503303964757709, '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': '7309540', 'n_tokens_mistral': 950, 'n_tokens_neox': 887, 'n_words': 192}