<commit_before>"use strict";

/*global nodeca, _*/



// fetch and prepare users info
// fired after each controllers
// list of user id should be prepared in controller
nodeca.filters.after('', function inject_users(params, next) {
  var env = this,
      user_id_list, result, UserModel;

  if (_.isArray(this.data.users) && this.data.users.length > 0) {

    env.extras.puncher.start('Users join');

    // There can be some garbage:
    // - empty ids (just because we push data without checks)
    // - duplicated ids(the same users from different objects)
    //
    // We remove dummy elements, let mongo filter unique values,
    // because it's more fast.
    user_id_list = _.compact(this.data.users);

    result = this.response.data.users = {};
    UserModel = nodeca.models.users.User;

    var fields = {
      _id:1,
      id:1,
      nickname:1
    };

    UserModel.where('_id').in(user_id_list).select(fields)
        .setOptions({ lean: true }).exec(function(err, user_list){
      user_list.forEach(function(user){
        result[user._id] = user;
      });

      env.extras.puncher.stop();
      
      next();
    });
  }
  else {
    next();
  }
});<commit_msg>users join: code cleanup + more debug info<commit_after>"use strict";

/*global nodeca, _*/



// fetch and prepare users info
// fired after each controllers
// list of user id should be prepared in controller
nodeca.filters.after('', function inject_users(params, next) {
  var env = this,
      user_id_list, result, UserModel;

  if (_.isArray(this.data.users) && this.data.users.length > 0) {

    // There can be some garbage:
    // - empty ids (just because we push data without checks)
    // - duplicated ids(the same users from different objects)
    //
    // We remove dummy elements, let mongo filter unique values,
    // because it's more fast.
    user_id_list = _.compact(this.data.users);

    env.extras.puncher.start('Users join', { count: user_id_list.length });

    result = this.response.data.users = {};

// uncomment to imitate empty users (to check template & speed)
//    env.extras.puncher.stop();
//    return next();

    UserModel = nodeca.models.users.User;

    var fields = [
      '_id', 'id', 'nickname'
    ];

    UserModel.where('_id').in(user_id_list).select(fields.join(' '))
        .setOptions({ lean: true }).exec(function(err, user_list){
      user_list.forEach(function(user){
        result[user._id] = user;
      });

      env.extras.puncher.stop();
      
      next();
    });
  }
  else {
    next();
  }
});
{'fraction_non_alphanumeric': 0.14083954491957631, 'fraction_numerical': 0.001961553550411926, 'mean_word_length': 2.642857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5166129', 'n_tokens_mistral': 819, 'n_tokens_neox': 784, 'n_words': 212}