<commit_before>import Ember from 'ember';
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(KeyboardShortcuts, AuthenticatedRouteMixin, {
  session: Ember.inject.service('session'),
  filters: Ember.inject.service('item-filters'),
  phoenix: Ember.inject.service('phoenix'),

  folderSorting: ['position'],
  sortedFolders: Ember.computed.sort('currentModel', 'folderSorting'),

  // Fetch current user data from the JWT session token and add it to the session.
  // Also connect to phoenix channels using the JWT token.
  beforeModel(transition) {
    this._super(transition);

    const token = this.get('session.data.authenticated.token');

    const data = this.getTokenData(token);
    this.get('session').set('data.user', data.user);

    if(!this.get('phoenix.socket').isConnected()) {
      var that = this;
      this.get('phoenix').connect(token).on('new', function(data) {
        // Run next loop to prevent race conditions.
        Ember.run.next(function() {
          that.store.pushPayload(data);
        });
      }).on('delete', function(data) {
        var record = that.store.peekRecord(data.type, data.id);
        if(record) {
          that.store.unloadRecord(record);
        }
      });
    }
  },

  // Extract JSON data from a JWT token.
  getTokenData(token) {
    const tokenData = atob(token.split('.')[1]);

    try {
      return JSON.parse(tokenData);
    } catch (e) {
      return tokenData;
    }
  },

  model() {
    return this.store.query('folder', {sort: 'position'});
  },

  setupController(controller, model) {
    this._super(controller, model);
    this.get('controller').set('filters', this.get('filters'));
  },

  keyboardShortcuts: {
    'h' : 'previousFeed',
    'l' : 'nextFeed',
    'i' : 'toggleReadVisibility',
    'r' : 'refreshData',
  },

  flatList: function() {
    var flatlist = ['items', 'favorites'];
    this.get('sortedFolders').forEach(function(folder) {<commit_msg>Workaround for Ember push race condition.<commit_after>import Ember from 'ember';
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(KeyboardShortcuts, AuthenticatedRouteMixin, {
  session: Ember.inject.service('session'),
  filters: Ember.inject.service('item-filters'),
  phoenix: Ember.inject.service('phoenix'),

  folderSorting: ['position'],
  sortedFolders: Ember.computed.sort('currentModel', 'folderSorting'),

  // Fetch current user data from the JWT session token and add it to the session.
  // Also connect to phoenix channels using the JWT token.
  beforeModel(transition) {
    this._super(transition);

    const token = this.get('session.data.authenticated.token');

    const data = this.getTokenData(token);
    this.get('session').set('data.user', data.user);

    if(!this.get('phoenix.socket').isConnected()) {
      var that = this;
      this.get('phoenix').connect(token).on('new', function(data) {
        // Run later to prevent race conditions.
        Ember.run.later(that, function() {
          console.log(data);
          this.store.pushPayload(data);
        }, 100);
      }).on('delete', function(data) {
        var record = that.store.peekRecord(data.type, data.id);
        if(record) {
          that.store.unloadRecord(record);
        }
      });
    }
  },

  // Extract JSON data from a JWT token.
  getTokenData(token) {
    const tokenData = atob(token.split('.')[1]);

    try {
      return JSON.parse(tokenData);
    } catch (e) {
      return tokenData;
    }
  },

  model() {
    return this.store.findAll('folder');
  },

  setupController(controller, model) {
    this._super(controller, model);
    this.get('controller').set('filters', this.get('filters'));
  },

  keyboardShortcuts: {
    'h' : 'previousFeed',
    'l' : 'nextFeed',
    'i' : 'toggleReadVisibility',
    'r' : 'refreshData',
  },

  flatList: function() {
    var flatlist = ['items', 'favorites'];
    this.get('sortedFolders').forEach(function(folder) {
{'fraction_non_alphanumeric': 0.15338882282996433, 'fraction_numerical': 0.0011890606420927466, 'mean_word_length': 3.399581589958159, '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': '7429790', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1310, 'n_words': 263}