<commit_before>import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import { all } from 'rsvp';

export default class CourseVisualizationsRoute extends Route.extend(AuthenticatedRouteMixin) {
  @service store;

  titleToken = '<PASSWORD>';

  /**
   * Prefetch related data to limit network requests
   */
  afterModel(model) {
    const courses = [model.get('id')];
    const course = model.get('id');
    const sessions = model.hasMany('sessions').ids();
    const existingSessionsInStore = this.store.peekAll('session');
    const existingSessionIds = existingSessionsInStore.mapBy('id');
    const unloadedSessions = sessions.filter(id => !existingSessionIds.includes(id));

    //if we have already loaded all of these sessions we can just proceed normally
    if (unloadedSessions.length === 0) {
      return;
    }

    const promises = [
      this.store.query('session', { filters: { course } }),
      this.store.query('offering', { filters: { courses } }),
      this.store.query('ilm-session', { filters: { courses } }),
      this.store.query('objective', { filters: { courses } }),
    ];
    const maximumSessionLoad = 100;
    if (sessions.length < maximumSessionLoad) {
      promises.pushObject(this.store.query('objective', { filters: { sessions } }));
      promises.pushObject(this.store.query('session-type', { filters: { sessions } }));
      promises.pushObject(this.store.query('term', { filters: { sessions } }));
    } else {
      for (let i = 0; i < sessions.length; i += maximumSessionLoad) {
        const slice = sessions.slice(i, i + maximumSessionLoad);
        promises.pushObject(this.store.query('objective', { filters: { sessions: slice } }));
        promises.pushObject(this.store.query('session-type', { filters: { sessions: slice } }));
        promises.pushObject(this.store.query('term', { filters: { sessions: slice } }));
      }
    }

    return all(promises);
  }
}
<commit_msg>preload session/course-objectives instead of legacy objectives.<commit_after>import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import { all } from 'rsvp';

export default class CourseVisualizationsRoute extends Route.extend(AuthenticatedRouteMixin) {
  @service store;

  titleToken = '<PASSWORD>';

  /**
   * Prefetch related data to limit network requests
   */
  afterModel(model) {
    const courses = [model.get('id')];
    const course = model.get('id');
    const sessions = model.hasMany('sessions').ids();
    const existingSessionsInStore = this.store.peekAll('session');
    const existingSessionIds = existingSessionsInStore.mapBy('id');
    const unloadedSessions = sessions.filter(id => !existingSessionIds.includes(id));

    //if we have already loaded all of these sessions we can just proceed normally
    if (unloadedSessions.length === 0) {
      return;
    }

    const promises = [
      this.store.query('session', { filters: { course } }),
      this.store.query('offering', { filters: { courses } }),
      this.store.query('ilm-session', { filters: { courses } }),
      this.store.query('course-objective', { filters: { courses } }),
    ];
    const maximumSessionLoad = 100;
    if (sessions.length < maximumSessionLoad) {
      promises.pushObject(this.store.query('session-objective', { filters: { sessions } }));
      promises.pushObject(this.store.query('session-type', { filters: { sessions } }));
      promises.pushObject(this.store.query('term', { filters: { sessions } }));
    } else {
      for (let i = 0; i < sessions.length; i += maximumSessionLoad) {
        const slice = sessions.slice(i, i + maximumSessionLoad);
        promises.pushObject(this.store.query('session-objective', { filters: { sessions: slice } }));
        promises.pushObject(this.store.query('session-type', { filters: { sessions: slice } }));
        promises.pushObject(this.store.query('term', { filters: { sessions: slice } }));
      }
    }

    return all(promises);
  }
}

{'fraction_non_alphanumeric': 0.14698162729658792, 'fraction_numerical': 0.0023860653781913625, 'mean_word_length': 3.6785714285714284, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '508470', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1211, 'n_words': 265}