<commit_before>import Ember from 'ember';
import Pouch from 'pouchdb';
import ENV from 'ember-api-docs/config/environment';

export default Ember.Service.extend({
  init() {
    this._super(...arguments);

    this._local = new Pouch('local_pouch');
    this._remote = new Pouch(ENV.COUCH_URL);
  },

  get(id) {
    const local = this._local;
    const remote = this._remote;

    return local.get(id).catch((err) => {
      if (err.status === 404) {
        return remote.get(id, {revs: true}).then((doc) => {
          return local.bulkDocs([doc], {new_edits: false});
        }).then(() => {
          return local.get(id);
        });
      }
    });
  },

  allDocs(ids, options={}) {
    const remote = this._remote;
    const local = this._local;

    const pouchOptions = Ember.$.extend({}, options, {include_docs: true, keys: ids});

    return local.allDocs(pouchOptions).then(documents => {
      const notFound = documents.rows.filter(doc => doc.error === 'not_found');

      if (notFound.length > 0) {
        const remotePouchOptions = Ember.$.extend({include_docs: true}, pouchOptions);
        return remote.allDocs(Ember.$.extend(remotePouchOptions, pouchOptions)).then((docs) => {
          const extractedDocs = extractDocuments(docs);
          return local.bulkDocs(extractedDocs.data, {new_edits: false});
        }).then(() => {
          return this.allDocs(ids, options);
        });
      }

      return extractDocuments(documents);
    });
  }
});

function extractDocuments(docs) {
  const data = docs.rows.map(row=> {
    const {doc} = row;
    return Ember.$.extend({}, doc.data, {
      _id: doc._id,
      _rev: doc._rev,
    });
  });
  return {data};
}
<commit_msg>fix more incongruities between allDocs and get<commit_after>import Ember from 'ember';
import Pouch from 'pouchdb';
import ENV from 'ember-api-docs/config/environment';

export default Ember.Service.extend({
  init() {
    this._super(...arguments);

    this._local = new Pouch('local_pouch');
    this._remote = new Pouch(ENV.COUCH_URL);
  },

  get(id) {
    const local = this._local;
    const remote = this._remote;

    return local.get(id).catch((err) => {
      if (err.status === 404) {
        return remote.get(id, {revs: true}).then((doc) => {
          return local.bulkDocs([doc], {new_edits: false});
        }).then(() => {
          return local.get(id);
        });
      }
    });
  },

  allDocs(ids, options={}) {
    const remote = this._remote;
    const local = this._local;

    const pouchOptions = Ember.$.extend({}, options, {include_docs: true, keys: ids});

    return local.allDocs(pouchOptions).then(documents => {
      const notFound = documents.rows.filter(doc => doc.error === 'not_found');

      if (notFound.length > 0) {
        const remotePouchOptions = Ember.$.extend({include_docs: true}, pouchOptions);
        return remote.allDocs(Ember.$.extend(remotePouchOptions, pouchOptions)).then((docs) => {
          const extractedDocs = extractDocuments(docs);
          return local.bulkDocs(extractedDocs.data, {new_edits: false});
        }).then(() => {
          return this.allDocs(ids, options);
        });
      }

      return {
        data: documents.rows.map(row => row.doc.data)
      }
    });
  }
});

function extractDocuments(docs) {
  const data = docs.rows.map(row=> row.doc);
  return {data};
}

{'fraction_non_alphanumeric': 0.1625483774933016, 'fraction_numerical': 0.0023816612086930635, 'mean_word_length': 2.7837837837837838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '103743', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1067, 'n_words': 219}