<commit_before>import Ember from 'ember';

export default Ember.ArrayProxy.extend({
  //Total count of rows
  totalCount: undefined,

  loadingCount: 0,

  // Function to get next chunk of rows.
  // The callback should return a promise which will return an array of rows.
  // The callback function should maintain the sequence of chunks,
  // first call to it should return first chunk, next call to it should return next chunk.
  callback: undefined,

  chunkSize: undefined,

  // This is a content or _lazyContent cache for sortable order
  _contentCache: Ember.computed(function() {
    var content = this.get('content');

    return content;
  }).property('content'),

  isEmberTableContent: true,

  init: function () {
    var totalCount = this.get('_totalCount');
    var lazyContent = new Array(totalCount);
    this.set('content', lazyContent);
  },

  fetchObjectAt: function (index) {
    var cacheContent = this.get('_contentCache');
    var chunkSize = this.get('chunkSize');
    if (!cacheContent[index] || cacheContent[index].get('isError')) {
      this.loadOneChunk(Math.floor(index / chunkSize));
    }
    this.tryPreload(index, chunkSize);
    return cacheContent[index];
  },

  length: Ember.computed.alias('_totalCount'),

  resetContent: function () {
    this.set('content', new Array(this.get('_totalCount')));
  },

  sort: function (sortingColumns) {
    this.set('content', sortingColumns.sortContent(this.get('content')));
  },

  loadOneChunk: function (chunkIndex) {
    var lazyContent = this.get('_contentCache');
    var chunkSize = this.get('chunkSize');
    var chunkStart = chunkIndex * chunkSize;
    var totalCount = this.get('_totalCount');
    var self = this;
    for (var x = 0; x < chunkSize && chunkStart + x < totalCount; x++) {
      if (!lazyContent[chunkStart + x]) {
        lazyContent[chunkStart + x] = Ember.ObjectProxy.create({"isLoaded": false, "isError": false});
      } else {
        lazyContent[chunkStart + x].setProperties({"isLoaded": false, "isError": false});
      }
    }
    this.incrementProperty('loadingCount');
    this.callback(chunkIndex, this.get('sortingColumns')).then(function (chunk) {
      lazyContent.slice(chunkStart, chunkStart + chunkSize)
        .forEach(function (row, x) {
          row.set('isLoaded', true);
          row.set('content', chunk[x]);
        });
      self.decrementProperty('loadingCount');
    }, function () {
      lazyContent.slice(chunkStart, chunkStart + chunkSize)
        .forEach(function (row) {
          row.set('isError', true);
        });
      self.decrementProperty('loadingCount');<commit_msg>remove 'contentCache'.<commit_after>import Ember from 'ember';

export default Ember.ArrayProxy.extend({
  //Total count of rows
  totalCount: undefined,

  loadingCount: 0,

  // Function to get next chunk of rows.
  // The callback should return a promise which will return an array of rows.
  // The callback function should maintain the sequence of chunks,
  // first call to it should return first chunk, next call to it should return next chunk.
  callback: undefined,

  chunkSize: undefined,

  isEmberTableContent: true,

  init: function () {
    var totalCount = this.get('_totalCount');
    var lazyContent = new Array(totalCount);
    this.set('content', lazyContent);
  },

  fetchObjectAt: function (index) {
    var content = this.get('content');
    var chunkSize = this.get('chunkSize');
    if (!content[index] || content[index].get('isError')) {
      this.loadOneChunk(Math.floor(index / chunkSize));
    }
    this.tryPreload(index, chunkSize);
    return content[index];
  },

  length: Ember.computed.alias('_totalCount'),

  resetContent: function () {
    this.set('content', new Array(this.get('_totalCount')));
  },

  sort: function (sortingColumns) {
    this.set('content', sortingColumns.sortContent(this.get('content')));
  },

  loadOneChunk: function (chunkIndex) {
    var content = this.get('content');
    var chunkSize = this.get('chunkSize');
    var chunkStart = chunkIndex * chunkSize;
    var totalCount = this.get('_totalCount');
    var self = this;
    for (var x = 0; x < chunkSize && chunkStart + x < totalCount; x++) {
      if (!content[chunkStart + x]) {
        content[chunkStart + x] = Ember.ObjectProxy.create({"isLoaded": false, "isError": false});
      } else {
        content[chunkStart + x].setProperties({"isLoaded": false, "isError": false});
      }
    }
    this.incrementProperty('loadingCount');
    this.callback(chunkIndex, this.get('sortingColumns')).then(function (chunk) {
      content.slice(chunkStart, chunkStart + chunkSize)
        .forEach(function (row, x) {
          row.set('isLoaded', true);
          row.set('content', chunk[x]);
        });
      self.decrementProperty('loadingCount');
    }, function () {
      content.slice(chunkStart, chunkStart + chunkSize)
        .forEach(function (row) {
          row.set('isError', true);
        });
      self.decrementProperty('loadingCount');
{'fraction_non_alphanumeric': 0.1394278855771154, 'fraction_numerical': 0.0008001600320064013, 'mean_word_length': 3.452359750667854, 'pattern_counts': {'":': 8, '<': 7, '<?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': '1175537', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1450, 'n_words': 368}