<commit_before>import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';

const { Mixin, assert, RSVP: { resolve }, isArray } = Ember;

export default Mixin.create({
  /* overridable properties/methods */
  autoReloadStrategy: 'incremental', // can be 'incremental' or 'fixed'

  autoReloadDelay: 30000,

  autoReloadMaximumDelay: 300000,
  autoReloadDelayGrowth: 2,

  willAutoReload(/* currentSnapshot */) { },
  didAutoReload(/* attributesChanged, newSnapshot, oldSnapshot */) { },

  shouldAutoReload(/* currentSnapshot */) {
    return true;
  },

  /* end overridable properties/methods */

  /* public api */

  startAutoReloading() {
    this.get('_autoReloadTask').perform();
  },

  stopAutoReloading() {
    this.get('_autoReloadTask').cancelAll();
  },

  /* end public api */

  unloadRecord() {
    this._super(...arguments);

    this.get('_autoReloadTask').cancelAll();
  },

  _autoReloadTask: task(function*() {
    let nextDelay = this._getNextReloadDelay(
      this.get('autoReloadDelay'),
      true);

    while (true) {
      yield timeout(nextDelay);

      let oldState = this._createSnapshot();

      if (this.get('isLoaded') &&
          !this.get('isDeleted')) {
        let shouldReload = yield resolve(this.shouldAutoReload(oldState));

        if (!shouldReload) {
          continue;
        }

        yield resolve(this.willAutoReload(oldState));
        yield this.reload();

        let newState = this._createSnapshot();

        let changeOccured = this._didAttributesChange(oldState.attributes(), newState.attributes());
        yield resolve(this.didAutoReload(changeOccured, newState, oldState));

        nextDelay = this._getNextReloadDelay(nextDelay, changeOccured);
      }
    }
  }).drop(),

  _getNextReloadDelay(currentDelay, attributesChanged) {
    let strategy = this.get('autoReloadStrategy');
    switch (strategy) {
      case 'fixed':
        return this.get('autoReloadDelay');
      case 'incremental':
        return attributesChanged ?
          this.get('autoReloadDelay') :
          Math.min(
            this.get('autoReloadMaximumDelay'),
            currentDelay * this.get('autoReloadDelayGrowth'));<commit_msg>fix potential mem leak<commit_after>import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';

const { Mixin, assert, RSVP: { resolve }, isArray } = Ember;

export default Mixin.create({
  /* overridable properties/methods */
  autoReloadStrategy: 'incremental', // can be 'incremental' or 'fixed'

  autoReloadDelay: 30000,

  autoReloadMaximumDelay: 300000,
  autoReloadDelayGrowth: 2,

  willAutoReload(/* currentSnapshot */) { },
  didAutoReload(/* attributesChanged, newSnapshot, oldSnapshot */) { },

  shouldAutoReload(/* currentSnapshot */) {
    return true;
  },

  /* end overridable properties/methods */

  /* public api */

  startAutoReloading() {
    this.get('_autoReloadTask').perform();
  },

  stopAutoReloading() {
    this.get('_autoReloadTask').cancelAll();
  },

  /* end public api */

  unloadRecord() {
    this._super(...arguments);

    this.get('_autoReloadTask').cancelAll();
  },

  _autoReloadTask: task(function*() {
    let nextDelay = this._getNextReloadDelay(
      this.get('autoReloadDelay'),
      true);

    while (true) {
      yield timeout(nextDelay);

      let oldState = this._createSnapshot();

      if (this.get('isLoaded') &&
          !this.get('isDeleted')) {
        let shouldReload = yield resolve(this.shouldAutoReload(oldState));

        if (!shouldReload) {
          continue;
        }

        yield resolve(this.willAutoReload(oldState));
        yield this.reload();

        let newState = this._createSnapshot();

        let changeOccured = this._didAttributesChange(oldState.attributes(), newState.attributes());
        yield resolve(this.didAutoReload(changeOccured, newState, oldState));

        nextDelay = this._getNextReloadDelay(nextDelay, changeOccured);
      } else {
        break;
      }
    }
  }).drop(),

  _getNextReloadDelay(currentDelay, attributesChanged) {
    let strategy = this.get('autoReloadStrategy');
    switch (strategy) {
      case 'fixed':
        return this.get('autoReloadDelay');
      case 'incremental':
        return attributesChanged ?
          this.get('autoReloadDelay') :
          Math.min(
            this.get('autoReloadMaximumDelay'),
            currentDelay * this.get('autoReloadDelayGrowth'));
{'fraction_non_alphanumeric': 0.13313809416535255, 'fraction_numerical': 0.005406623113313809, 'mean_word_length': 3.11873840445269, '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': '2075135', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1298, 'n_words': 248}