<commit_before>import angular from 'angular';
import _ from 'lodash';

class MixedDatasource {
  /** @ngInject */
  constructor(private $q, private datasourceSrv) {}

  query(options) {
    const sets = _.groupBy(options.targets, 'datasource');
    const promises = _.map(sets, targets => {
      const dsName = targets[0].datasource;
      if (dsName === '-- Mixed --') {
        return this.$q([]);
      }

      return this.datasourceSrv.get(dsName).then(ds => {
        const opt = angular.copy(options);
        opt.targets = targets;
        return ds.query(opt);
      });
    });

    return this.$q.all(promises).then(results => {
      return { data: _.flatten(_.map(results, 'data')) };
    });
  }
}

export { MixedDatasource, MixedDatasource as Datasource };<commit_msg>datasource: fix disable query when using mixed datasource (#16409)<commit_after>import angular from 'angular';
import _ from 'lodash';

class MixedDatasource {
  /** @ngInject */
  constructor(private $q, private datasourceSrv) {}

  query(options) {
    const sets = _.groupBy(options.targets, 'datasource');
    const promises = _.map(sets, targets => {
      const dsName = targets[0].datasource;
      if (dsName === '-- Mixed --') {
        return this.$q([]);
      }

      const filtered = _.filter(targets, t => {
        return !t.hide;
      });

      if (filtered.length === 0) {
        return { data: [] };
      }

      return this.datasourceSrv.get(dsName).then(ds => {
        const opt = angular.copy(options);
        opt.targets = filtered;
        return ds.query(opt);
      });
    });

    return this.$q.all(promises).then(results => {
      return { data: _.flatten(_.map(results, 'data')) };
    });
  }
}

export { MixedDatasource, MixedDatasource as Datasource };
{'fraction_non_alphanumeric': 0.1580427446569179, 'fraction_numerical': 0.0044994375703037125, 'mean_word_length': 2.6832298136645965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '7384940', 'n_tokens_mistral': 584, 'n_tokens_neox': 545, 'n_words': 121}