<commit_before>import RestModel from 'discourse/models/rest';
import ResultSet from 'discourse/models/result-set';

let _identityMap;

// You should only call this if you're a test scaffold
function flushMap() {
  _identityMap = {};
}

function storeMap(type, id, obj) {
  if (!id) { return; }

  _identityMap[type] = _identityMap[type] || {};
  _identityMap[type][id] = obj;
}

function fromMap(type, id) {
  const byType = _identityMap[type];
  if (byType) { return byType[id]; }
}

function removeMap(type, id) {
  const byType = _identityMap[type];
  if (byType) { delete byType[id]; }
}

function findAndRemoveMap(type, id) {
  const byType = _identityMap[type];
  if (byType) {
    const result = byType[id];
    delete byType[id];
    return result;
  }
}

flushMap();

export default Ember.Object.extend({
  plurals: {},
  pluralize(thing) {
    if (this.get('plurals')[thing]) {
      return this.get('plurals')[thing];
    }
    return thing + "s";
  },

  addPluralization(thing, plural) {
    this.get('plurals')[thing] = plural;
  },

  findAll(type) {
    const self = this;
    return this.adapterFor(type).findAll(this, type).then(function(result) {
      return self._resultSet(type, result);
    });
  },

  // Mostly for legacy, things like TopicList without ResultSets
  findFiltered(type, findArgs) {
    const self = this;
    return this.adapterFor(type).find(this, type, findArgs).then(function(result) {
      return self._build(type, result);
    });
  },

  find(type, findArgs) {
    const self = this;
    return this.adapterFor(type).find(this, type, findArgs).then(function(result) {
      if (typeof findArgs === "object") {
        return self._resultSet(type, result);
      } else {
        return self._hydrate(type, result[Ember.String.underscore(type)], result);
      }
    });
  },

  refreshResults(resultSet, type, url) {<commit_msg>Use the underscore-private convention, simplify<commit_after>import RestModel from 'discourse/models/rest';
import ResultSet from 'discourse/models/result-set';

let _identityMap;

// You should only call this if you're a test scaffold
function flushMap() {
  _identityMap = {};
}

function storeMap(type, id, obj) {
  if (!id) { return; }

  _identityMap[type] = _identityMap[type] || {};
  _identityMap[type][id] = obj;
}

function fromMap(type, id) {
  const byType = _identityMap[type];
  if (byType) { return byType[id]; }
}

function removeMap(type, id) {
  const byType = _identityMap[type];
  if (byType) { delete byType[id]; }
}

function findAndRemoveMap(type, id) {
  const byType = _identityMap[type];
  if (byType) {
    const result = byType[id];
    delete byType[id];
    return result;
  }
}

flushMap();

export default Ember.Object.extend({
  _plurals: {},
  pluralize(thing) {
    return this._plurals[thing] || thing + "s";
  },

  addPluralization(thing, plural) {
    this._plurals[thing] = plural;
  },

  findAll(type) {
    const self = this;
    return this.adapterFor(type).findAll(this, type).then(function(result) {
      return self._resultSet(type, result);
    });
  },

  // Mostly for legacy, things like TopicList without ResultSets
  findFiltered(type, findArgs) {
    const self = this;
    return this.adapterFor(type).find(this, type, findArgs).then(function(result) {
      return self._build(type, result);
    });
  },

  find(type, findArgs) {
    const self = this;
    return this.adapterFor(type).find(this, type, findArgs).then(function(result) {
      if (typeof findArgs === "object") {
        return self._resultSet(type, result);
      } else {
        return self._hydrate(type, result[Ember.String.underscore(type)], result);
      }
    });
  },

  refreshResults(resultSet, type, url) {
{'fraction_non_alphanumeric': 0.1447014523937601, 'fraction_numerical': 0.0, 'mean_word_length': 3.6545682102628287, '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': '3396263', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1236, 'n_words': 281}