Browse Source

EAGLESIX-3087: Changes to Pipeline.js class based on comments

Jason Walton 11 years ago
parent
commit
0741db4306
1 changed files with 12 additions and 14 deletions
  1. 12 14
      lib/pipeline/Pipeline.js

+ 12 - 14
lib/pipeline/Pipeline.js

@@ -16,8 +16,6 @@ var Pipeline = module.exports = function Pipeline(theCtx){
 	this.SYNC_MODE = false;
 }, klass = Pipeline, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
-var DepsTracker = require("./DepsTracker");
-
 var DocumentSource = require("./documentSources/DocumentSource"),
 	LimitDocumentSource = require('./documentSources/LimitDocumentSource'),
 	MatchDocumentSource = require('./documentSources/MatchDocumentSource'),
@@ -191,6 +189,7 @@ proto.splitForSharded = function splitForSharded() {
 	klass.optimizations.sharded.findSplitPoint(shardPipeline, this);
 	klass.optimizations.sharded.moveFinalUnwindFromShardsToMerger(shardPipeline, this);
 	//klass.optimizations.sharded.limitFieldsSentFromShardsToMerger(shardPipeline, this);
+	return shardPipeline;
 };
 
 /**
@@ -298,10 +297,9 @@ klass.parseDocumentSources = function parseDocumentSources(pipeline, ctx){
 
 		// Create a DocumentSource pipeline stage from 'stageSpec'.
 		var desc = klass.stageDesc[stageName];
-		if (!desc) throw new Error("Unrecognized pipeline stage name: '" + stageName + "'; code 16436");
+		if (!desc) throw new Error("Unrecognized pipeline stage name: '" + stageName + "'; uassert code 16436");
 
 		// Parse the stage
-		debugger
 		var stage = desc(stageSpec, ctx);
 		if (!stage) throw new Error("Stage must not be undefined!"); // verify(stage)
 		sources.push(stage);
@@ -381,7 +379,7 @@ function ifError(err) {
  */
 proto.getInitialQuery = function getInitialQuery() {
 	var sources = this.sources;
-	if((sources == null) || (sources.length === 0)) {
+	if(sources.length === 0) {
 		return {};
 	}
 
@@ -404,9 +402,10 @@ proto.serialize = function serialize() {
 		array = [];
 
 	// create an array out of the pipeline operations
-	this.sources.forEach(function(source) {
+	for (var source in this.sources) {
+	//this.sources.forEach(function(source) {
 		source.serializeToArray(array);
-	});
+	}
 
 	serialized[klass.COMMAND_NAME] = this.ctx && this.ctx.ns && this.ctx.ns.coll ? this.ctx.ns.coll : '';
 	serialized[klass.PIPELINE_NAME] = array;
@@ -527,7 +526,9 @@ proto.addInitialSource = function addInitialSource(source) {
 
 //SKIPPED: canRunInMongos
 
-proto.getDependencies = function getDependencies (initialQuery) {
+//Note: Deviation from Mongo: Mongo 2.6.5 passes a param to getDependencies
+//	to calculate TextScore.  mungedb-aggregate doesn't do this, so no param is needed.
+proto.getDependencies = function getDependencies () {
     var deps = new DepsTracker(), 
 		knowAllFields = false;
 
@@ -544,12 +545,9 @@ proto.getDependencies = function getDependencies (initialQuery) {
         }
 
         if (!knowAllFields) {
-            //C++ insert this range: deps.fields.insert(localDeps.fields.begin(), localDeps.fields.end());
-            var keys = Object.keys(localDeps.fields);
-        	for (var j = 0; j < keys.length; j++) {
-        		var key = keys[j];
-        		deps.fields[key] = localDeps.fields[key];
-        	}
+            for (var key in localDeps.fields)
+            	deps.fields[key] = localDeps.fields[key];
+
             if (localDeps.needWholeDocument)
                 deps.needWholeDocument = true;
             knowAllFields = status & DocumentSource.GetDepsReturn.EXHAUSTIVE_FIELDS;