<commit_before>angular.module('codebrag.commits')

    .factory('pendingCommitsListService', function(Commits, $rootScope, events, $q) {

        var pageLimit = 7;

        var nextCommits;
        var prefetchedCommitPromise;

        var commits = [];
        codebrag.commitsList.mixin.withBulkElementsManipulation.call(commits);
        codebrag.commitsList.mixin.withMarkingAsReviewed.call(commits);
        codebrag.commitsList.mixin.withIndexOperations.call(commits);

        var eventsEmitter = codebrag.commitsList.mixin.eventsEmitter($rootScope, events);

        function loadCommits() {
            return Commits.queryReviewable({limit: pageLimit}).$then(function(response) {
                commits.replaceWith(response.data.commits);
                nextCommits = response.data.newer;
                _prefetchOneMoreCommit();
                eventsEmitter.triggerAsyncCommitsCounterRefresh();
                return commits;
            });
        }

        function commitDetails(commitId) {
            return Commits.get({commitId: commitId}).$then(function(response) {
                return response.data;
            });
        }

        function markAsReviewed(commitId) {
            Commits.remove({commitId: commitId});   // fire and don't wait for response
            return prefetchedCommitPromise.then(function(prefetchedCommit) {
                var indexRemoved = commits.removeFromListBy(commitId);
                prefetchedCommit && commits.push(prefetchedCommit);
                eventsEmitter.triggerCounterDecrease();
                _prefetchOneMoreCommit();
                return commits.elementAtIndexOrLast(indexRemoved);
            });
        }

        function loadNextCommits() {
            if(!commits.length) return;
            var options = {min_id: commits.last().id, limit: pageLimit, filter: 'to_review'};
            Commits.query(options).$then(function(response) {
                commits.appendAll(response.data.commits);
                nextCommits = response.data.newer;<commit_msg>Fix reviewed commit returning back.<commit_after>angular.module('codebrag.commits')

    .factory('pendingCommitsListService', function(Commits, $rootScope, events, $q) {

        var pageLimit = 7;

        var nextCommits;
        var prefetchedCommitPromise;

        var commits = [];
        codebrag.commitsList.mixin.withBulkElementsManipulation.call(commits);
        codebrag.commitsList.mixin.withMarkingAsReviewed.call(commits);
        codebrag.commitsList.mixin.withIndexOperations.call(commits);

        var eventsEmitter = codebrag.commitsList.mixin.eventsEmitter($rootScope, events);

        function loadCommits() {
            return Commits.queryReviewable({limit: pageLimit}).$then(function(response) {
                commits.replaceWith(response.data.commits);
                nextCommits = response.data.newer;
                _prefetchOneMoreCommit();
                eventsEmitter.triggerAsyncCommitsCounterRefresh();
                return commits;
            });
        }

        function commitDetails(commitId) {
            return Commits.get({commitId: commitId}).$then(function(response) {
                return response.data;
            });
        }

        function markAsReviewed(commitId) {
            function removeGivenAndAppendPrefetchedCommit(prefetchedCommit) {
                var indexRemoved = commits.removeFromListBy(commitId);
                prefetchedCommit && commits.push(prefetchedCommit);
                eventsEmitter.triggerCounterDecrease();
                return commits.elementAtIndexOrLast(indexRemoved);
            }

            var commitMarkedAsReviewed =Commits.remove({commitId: commitId}).$then(function() {
                return prefetchedCommitPromise;
            });
            var nextCommitToReview = commitMarkedAsReviewed.then(removeGivenAndAppendPrefetchedCommit)
            nextCommitToReview.then(_prefetchOneMoreCommit);
            return nextCommitToReview;
        }

        function loadNextCommits() {
            if(!commits.length) return;
            var options = {min_id: commits.last().id, limit: pageLimit, filter: 'to_review'};
            Commits.query(options).$then(function(response) {
                commits.appendAll(response.data.commits);
                nextCommits = response.data.newer;
{'fraction_non_alphanumeric': 0.09593757172366307, 'fraction_numerical': 0.0004590314436538903, 'mean_word_length': 2.3993759750390016, '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': '6958960', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1144, 'n_words': 162}