<commit_before>var codebrag = codebrag || {};

/**
 * Implementation of angularjs decorator around $http service.
 * This decorator drops request if the same request is already in progress. By default all requests are passed through.
 * To make use of it set 'unique' option on $http request to 'true' and provide 'requestId'
 * Requests with duplicated 'requestId' are dropped and rejected with promise containing 499 HTTP status code
 * @param $http - original angular http service
 * @param $q - promises service to build and reject promise when request is dropped
 * @returns {Function} modified http service
 */
codebrag.uniqueRequestsAwareHttpService = function($http, $q) {

    var DUPLICATED_REQUEST_STATUS_CODE = 499;
    var EMPTY_BODY = '';
    var EMPTY_HEADERS = {};

    var uniqueRequestOptionName = "unique";
    var requestIdOptionName = 'requestId';

    function checkForDuplicates(requestConfig) {
        return !!requestConfig[uniqueRequestOptionName];
    }

    function checkIfDuplicated(requestConfig) {
        var duplicated = $http.pendingRequests.filter(function(pendingReqConfig) {
            return pendingReqConfig[requestIdOptionName] && pendingReqConfig[requestIdOptionName] === requestConfig[requestIdOptionName];
        });
        return duplicated.length > 0;
    }

    function buildRejectedRequestPromise(requestConfig) {
        var dfd = $q.defer();
        var response = {data: EMPTY_BODY, headers: EMPTY_HEADERS, status: DUPLICATED_REQUEST_STATUS_CODE, config: requestConfig};
        console.info('Such request is already in progres, rejecting this one with', response);
        dfd.reject(response);
        return dfd.promise;
    }


    function registerShortcutMethods(modifiedService) {
        ['get', 'delete', 'head', 'jsonp'].forEach(function (name) {
            modifiedService[name] = function (url, config) {
                return modifiedService(extend(config || {}, {
                    method: name,
                    url: url
                }));
            };
        });
        ['post', 'put'].forEach(function (name) {
            modifiedService[name] = function (url, data, config) {
                return modifiedService(extend(config || {}, {
                    method: name,
                    url: url,
                    data: data
                }));
            };
        });
    }

    var modifiedHttpService = function(requestConfig) {
        if(checkForDuplicates(requestConfig) && checkIfDuplicated(requestConfig)) {
            return buildRejectedRequestPromise(requestConfig);
        }
        return $http(requestConfig);
    };
    registerShortcutMethods(modifiedHttpService);
    return modifiedHttpService;
};<commit_msg>Expose http pending requests collection on decorating service.<commit_after>var codebrag = codebrag || {};

/**
 * Implementation of angularjs decorator around $http service.
 * This decorator drops request if the same request is already in progress. By default all requests are passed through.
 * To make use of it set 'unique' option on $http request to 'true' and provide 'requestId'
 * Requests with duplicated 'requestId' are dropped and rejected with promise containing 499 HTTP status code
 * @param $http - original angular http service
 * @param $q - promises service to build and reject promise when request is dropped
 * @returns {Function} modified http service
 */
codebrag.uniqueRequestsAwareHttpService = function($http, $q) {

    var DUPLICATED_REQUEST_STATUS_CODE = 499;
    var EMPTY_BODY = '';
    var EMPTY_HEADERS = {};

    var uniqueRequestOptionName = "unique";
    var requestIdOptionName = 'requestId';

    function checkForDuplicates(requestConfig) {
        return !!requestConfig[uniqueRequestOptionName];
    }

    function checkIfDuplicated(requestConfig) {
        var duplicated = $http.pendingRequests.filter(function(pendingReqConfig) {
            return pendingReqConfig[requestIdOptionName] && pendingReqConfig[requestIdOptionName] === requestConfig[requestIdOptionName];
        });
        return duplicated.length > 0;
    }

    function buildRejectedRequestPromise(requestConfig) {
        var dfd = $q.defer();
        var response = {data: EMPTY_BODY, headers: EMPTY_HEADERS, status: DUPLICATED_REQUEST_STATUS_CODE, config: requestConfig};
        console.info('Such request is already in progres, rejecting this one with', response);
        dfd.reject(response);
        return dfd.promise;
    }


    function registerShortcutMethods(modifiedService) {
        ['get', 'delete', 'head', 'jsonp'].forEach(function (name) {
            modifiedService[name] = function (url, config) {
                return modifiedService(extend(config || {}, {
                    method: name,
                    url: url
                }));
            };
        });
        ['post', 'put'].forEach(function (name) {
            modifiedService[name] = function (url, data, config) {
                return modifiedService(extend(config || {}, {
                    method: name,
                    url: url,
                    data: data
                }));
            };
        });
    }

    function delegatePendingRequestsCollection(modifiedHttpService) {
        modifiedHttpService.pendingRequests = $http.pendingRequests;
    }

    var modifiedHttpService = function(requestConfig) {
        if(checkForDuplicates(requestConfig) && checkIfDuplicated(requestConfig)) {
            return buildRejectedRequestPromise(requestConfig);
        }
        return $http(requestConfig);
    };
    registerShortcutMethods(modifiedHttpService);
    delegatePendingRequestsCollection(modifiedHttpService);

    return modifiedHttpService;
};
{'fraction_non_alphanumeric': 0.09432971648582429, 'fraction_numerical': 0.002450122506125306, 'mean_word_length': 2.864097363083164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5454153', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1421, 'n_words': 392}