<commit_before>const _ = require('underscore');
const Backbone = require('backbone');
const batchProcessItems = require('dashboard/helpers/batch-process-items');
const checkAndBuildOpts = require('builder/helpers/required-opts');

const REQUIRED_OPTS = [
  'contentType'
];

/**
 * View model for delete items view.
 * Manages the states changes for the delete items view.
 */
module.exports = Backbone.Collection.extend({
  initialize: function (models, options) {
    checkAndBuildOpts(options, REQUIRED_OPTS, this);
  },

  state: function () {
    return this._state;
  },

  errorMessage: function () {
    return this._errorMessage;
  },

  setState: function (newState) {
    this._state = newState;
    this.trigger('change');
    this.trigger(newState);
  },

  isDeletingDatasets: function () {
    return this._contentType === 'datasets';
  },

  loadPrerequisites: function () {
    const setStateToConfirmDeletion = this.setState.bind(this, 'ConfirmDeletion');

    if (this.isDeletingDatasets()) {
      this.setState('LoadingPrerequisites');

      batchProcessItems({
        howManyInParallel: 5,
        items: this.toArray(),
        processItem: this._loadPrerequisitesForModel,
        done: setStateToConfirmDeletion,
        fail: this.setState.bind(this, 'LoadPrerequisitesFail')
      });
    } else {
      setStateToConfirmDeletion();
    }
  },

  affectedEntities: function () {
    return this.chain()
      .map(function (m) {
        return m.sharedWithEntities();
      })
      .flatten().compact().value();
  },

  affectedVisData: function () {
    const visData = this.chain()
      .map(function (m) {<commit_msg>Set a limit of 1 requests in parallel getting tables information<commit_after>const _ = require('underscore');
const Backbone = require('backbone');
const batchProcessItems = require('dashboard/helpers/batch-process-items');
const checkAndBuildOpts = require('builder/helpers/required-opts');

const REQUIRED_OPTS = [
  'contentType'
];

/**
 * View model for delete items view.
 * Manages the states changes for the delete items view.
 */
module.exports = Backbone.Collection.extend({
  initialize: function (models, options) {
    checkAndBuildOpts(options, REQUIRED_OPTS, this);
  },

  state: function () {
    return this._state;
  },

  errorMessage: function () {
    return this._errorMessage;
  },

  setState: function (newState) {
    this._state = newState;
    this.trigger('change');
    this.trigger(newState);
  },

  isDeletingDatasets: function () {
    return this._contentType === 'datasets';
  },

  loadPrerequisites: function () {
    const setStateToConfirmDeletion = this.setState.bind(this, 'ConfirmDeletion');

    if (this.isDeletingDatasets()) {
      this.setState('LoadingPrerequisites');

      // INFO: Don't request more than 3 in parallel to avoid
      // getting 429 due to the API rate limit
      batchProcessItems({
        howManyInParallel: 1,
        items: this.toArray(),
        processItem: this._loadPrerequisitesForModel,
        done: setStateToConfirmDeletion,
        fail: this.setState.bind(this, 'LoadPrerequisitesFail')
      });
    } else {
      setStateToConfirmDeletion();
    }
  },

  affectedEntities: function () {
    return this.chain()
      .map(function (m) {
        return m.sharedWithEntities();
      })
      .flatten().compact().value();
  },

  affectedVisData: function () {
    const visData = this.chain()
      .map(function (m) {
{'fraction_non_alphanumeric': 0.1265164644714038, 'fraction_numerical': 0.002021952628538417, 'mean_word_length': 3.3780025284450064, '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': '2898277', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1026, 'n_words': 222}