<commit_before>import Ember from 'ember';
import AjaxPromise from '../utils/ajax-promise';
import config from '../config/environment';

export default Ember.Mixin.create({

  preloadData: function(includePublicTypes) {
    var promises = [];
    var isDonorApp = this.get("session.isDonorApp");

    var retrieve = types => types.map(type => this.store.findAll(type, { reload: true }));

    if (includePublicTypes && isDonorApp) {
      promises = retrieve(config.APP.PRELOAD_TYPES);
    }

    if (this.get("session.authToken")) {
      promises.push(
        new AjaxPromise("/auth/current_user_profile", "GET", this.session.get("authToken"))
          .then(data => {
            this.store.pushPayload(data);
            this.store.pushPayload({ user: data.user_profile });
            this.notifyPropertyChange("session.currentUser");
          })
      );

      var offer_params = this.session.get("isAdminApp") ?
        { states: ["nondraft"], summarize: true }:
        { states: ["for_donor"] };
      promises.push(
        this.store.query('offer', offer_params)
      );

      if(isDonorApp) {
        promises = promises.concat(retrieve(config.APP.PRELOAD_AUTHORIZED_TYPES));
      }
    }

    return Ember.RSVP.all(promises);
  },

  loadStaticData: function(includePublicTypes) {
    var promises = [];
    var retrieve = types => types.map(type => this.store.findAll(type, { reload: true }));
    if (includePublicTypes) { promises = retrieve(config.APP.PRELOAD_TYPES); }
    if (this.get("session.authToken")) {
      promises = promises.concat(retrieve(config.APP.PRELOAD_AUTHORIZED_TYPES));
    }
    return Ember.RSVP.all(promises);
  }
});<commit_msg>Load unread messages for Admin app<commit_after>import Ember from "ember";
import AjaxPromise from "../utils/ajax-promise";
import config from "../config/environment";

export default Ember.Mixin.create({
  preloadData(includePublicTypes) {
    var promises = [];
    var isDonorApp = this.get("session.isDonorApp");

    var retrieve = types =>
      types.map(type => this.store.findAll(type, { reload: true }));

    if (includePublicTypes && isDonorApp) {
      promises = retrieve(config.APP.PRELOAD_TYPES);
    }

    if (this.get("session.authToken")) {
      promises.push(
        new AjaxPromise(
          "/auth/current_user_profile",
          "GET",
          this.session.get("authToken")
        ).then(data => {
          this.store.pushPayload(data);
          this.store.pushPayload({ user: data.user_profile });
          this.notifyPropertyChange("session.currentUser");
        })
      );

      var offer_params = this.session.get("isAdminApp")
        ? { states: ["nondraft"], summarize: true }
        : { states: ["for_donor"] };
      promises.push(this.store.query("offer", offer_params));

      if (isDonorApp) {
        promises = promises.concat(
          retrieve(config.APP.PRELOAD_AUTHORIZED_TYPES)
        );
      }
    }

    return Ember.RSVP.all(promises).then(results => {
      this.runBackgroundTasks();
      return results;
    });
  },

  runBackgroundTasks() {
    // We don't wait for the following tasks to return
    if (this.session.get("isAdminApp")) {
      this.loadUnreadMessages();
    }
  },

  loadUnreadMessages() {
    let batchSize = 20;
    let offerIds = this.store.peekAll("offer").mapBy("id");
    let promises = [];

    while (offerIds.length) {
      let batch = offerIds.splice(0, batchSize);
      promises.push(
        this.store.query("message", {
          state: "unread",
          offer_id: batch.join(",")
        })
      );
    }

    return Ember.RSVP.all(promises);
  },

  loadStaticData(includePublicTypes) {
    var promises = [];
    var retrieve = types =>
      types.map(type => this.store.findAll(type, { reload: true }));
    if (includePublicTypes) {
      promises = retrieve(config.APP.PRELOAD_TYPES);
    }
    if (this.get("session.authToken")) {
      promises = promises.concat(retrieve(config.APP.PRELOAD_AUTHORIZED_TYPES));
    }
    return Ember.RSVP.all(promises);
  }
});
{'fraction_non_alphanumeric': 0.14602861371484954, 'fraction_numerical': 0.0007400098667982239, 'mean_word_length': 2.7861811391223155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '5418000', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1258, 'n_words': 214}