<commit_before>var db = require("./db");
var util = require("./util");
var srv = require("./server");
var api = require("./api");
var async = require("async");

var _ = require("underscore");

var constraints={};
var plugins = {};
var stopwords;

exports.init = function(){
		
	constraints[srv.config.db.default_catalog] = {pre:{}, post:{}}; 
	plugins[srv.config.db.default_catalog] = {_in:{},_out:{},_mid:{}};	
	stopwords = util.read_lines(srv.config.app.stopwords_file);
}

/*
 * Load doc and user from db.
 */
function load_objects(ctx, ret_handler){					
	
	async.parallel(
		[function(next){//load document
			
			if(ctx.params && ctx.params.wid && ctx.doc === undefined ){
				
				db.select(ctx.params.catalog, ctx.params.wid,{_id:1,ctime:1,etime:1,rcpts:1,push_id:1,push_type:1}, function(err,doc){
					
					ctx.doc = doc;
					if(!err && !doc)
						next({code:-1, message:"Document not found: #" + ctx.params.catalog + "/" + ctx.params.wid }, null);	
					else													
						next(err);
								
				});
			}else
				next();
		},
		
		function(next){//load user
			
			if(ctx.params && ctx.params.uid && ctx.user === undefined){
				
				db.select("users",ctx.params.uid,function(err,user){
					
					ctx.user = user;					
					if( !err && !user){							
						next({code:-1, message:"User not found: #users/" + ctx.params.uid });
					}else						
						next(err);
						
				});
			}else
				next();
			
		}],function(err){			
			ret_handler(err);
		}
	);	
	
}


/*
 * Add a plugin for incoming, middle or outgoing phase step. 
 */
function add_plugin(plugins, proc_name, plugin_name, func_handler){
	
	if(!plugins[proc_name])
		plugins[proc_name] = {};<commit_msg>added projection(_id,wids,push_id,push_type) to user load when params.uid is provided.<commit_after>var db = require("./db");
var util = require("./util");
var srv = require("./server");
var api = require("./api");
var async = require("async");

var _ = require("underscore");

var constraints={};
var plugins = {};
var stopwords;

exports.init = function(){
		
	constraints[srv.config.db.default_catalog] = {pre:{}, post:{}}; 
	plugins[srv.config.db.default_catalog] = {_in:{},_out:{},_mid:{}};	
	stopwords = util.read_lines(srv.config.app.stopwords_file);
}

/*
 * Load doc and user from db.
 */
function load_objects(ctx, ret_handler){					
	
	async.parallel(
		[function(next){//load document
			
			if(ctx.params && ctx.params.wid && ctx.doc === undefined ){
				
				db.select(ctx.params.catalog, ctx.params.wid,{_id:1,ctime:1,etime:1,rcpts:1}, function(err,doc){
					
					ctx.doc = doc;
					if(!err && !doc)
						next({code:-1, message:"Document not found: #" + ctx.params.catalog + "/" + ctx.params.wid }, null);	
					else													
						next(err);
								
				});
			}else
				next();
		},
		
		function(next){//load user
			
			if(ctx.params && ctx.params.uid && ctx.user === undefined){
				
				db.select("users",ctx.params.uid,{_id:1,wids:1,push_id:1,push_type:1},function(err,user){
					
					ctx.user = user;					
					if( !err && !user){							
						next({code:-1, message:"User not found: #users/" + ctx.params.uid });
					}else						
						next(err);
						
				});
			}else
				next();
			
		}],function(err){			
			ret_handler(err);
		}
	);	
	
}


/*
 * Add a plugin for incoming, middle or outgoing phase step. 
 */
function add_plugin(plugins, proc_name, plugin_name, func_handler){
	
	if(!plugins[proc_name])
		plugins[proc_name] = {};
{'fraction_non_alphanumeric': 0.1861609727851766, 'fraction_numerical': 0.0052113491603937466, 'mean_word_length': 2.895152198421646, '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': '567301', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1180, 'n_words': 222}