main_chain.js
function createListOfBestChildren(arrParentUnits, handleBestChildrenList){
		if (arrParentUnits.length === 0)
			return handleBestChildrenList([]);
		var arrBestChildren = arrParentUnits.slice();
		
		function goDownAndCollectBestChildren(arrStartUnits, cb){
			conn.query("SELECT unit, is_free FROM units WHERE best_parent_unit IN(?)", [arrStartUnits], function(rows){
				if (rows.length === 0)
					return cb();
				//console.log("unit", arrStartUnits, "best children:", rows.map(function(row){ return row.unit; }), "free units:", rows.reduce(function(sum, row){ return sum+row.is_free; }, 0));
				async.eachSeries(
					rows, 
					function(row, cb2){
						arrBestChildren.push(row.unit);
						if (row.is_free === 1)
							cb2();
						else
							goDownAndCollectBestChildren([row.unit], cb2);
					},
					cb
				);
			});
		}
		
		goDownAndCollectBestChildren(arrParentUnits, function(){
			handleBestChildrenList(arrBestChildren);
		});
	}
function createListOfBestChildren(arrParentUnits, handleBestChildrenList){
		if (arrParentUnits.length === 0)
			return handleBestChildrenList([]);
		var arrBestChildren = arrParentUnits.slice();
		
		function goDownAndCollectBestChildren(arrStartUnits, cb){
			conn.query("SELECT unit, is_free FROM units WHERE best_parent_unit IN(?)", [arrStartUnits], function(rows){
				if (rows.length === 0)
					return cb();
				//console.log("unit", arrStartUnits, "best children:", rows.map(function(row){ return row.unit; }), "free units:", rows.reduce(function(sum, row){ return sum+row.is_free; }, 0));
				async.eachSeries(
					rows, 
					function(row, cb2){
						arrBestChildren.push(row.unit);
						if (row.is_free === 1)
							cb2();
						else
							goDownAndCollectBestChildren([row.unit], cb2);
					},
					cb
				);
			});
		}
		
		goDownAndCollectBestChildren(arrParentUnits, function(){
			handleBestChildrenList(arrBestChildren);
		});
	}
function createListOfBestChildren ( arrParentUnits , handleBestChildrenList ) { if ( arrParentUnits . length === 0 ) return handleBestChildrenList ( [ ] ) ; var arrBestChildren = arrParentUnits . slice ( ) ; function goDownAndCollectBestChildren ( arrStartUnits , cb ) { conn . query ( "SELECT unit, is_free FROM units WHERE best_parent_unit IN(?)" , [ arrStartUnits ] , function ( rows ) { if ( rows . length === 0 ) return cb ( ) ; //console.log("unit", arrStartUnits, "best children:", rows.map(function(row){ return row.unit; }), "free units:", rows.reduce(function(sum, row){ return sum+row.is_free; }, 0)); async . eachSeries ( rows , function ( row , cb2 ) { arrBestChildren . push ( row . unit ) ; if ( row . is_free === 1 ) cb2 ( ) ; else goDownAndCollectBestChildren ( [ row . unit ] , cb2 ) ; } , cb ) ; } ) ; } goDownAndCollectBestChildren ( arrParentUnits , function ( ) { handleBestChildrenList ( arrBestChildren ) ; } ) ; }
also includes arrParentUnits
also includes arrParentUnits