Explorar o código

EAGLESIX-2892 fixed loops, formatting

Austin Meagher %!s(int64=11) %!d(string=hai) anos
pai
achega
f22ee02d64
Modificáronse 2 ficheiros con 9 adicións e 9 borrados
  1. 8 8
      lib/pipeline/DepsTracker.js
  2. 1 1
      test/lib/pipeline/DepsTracker.js

+ 8 - 8
lib/pipeline/DepsTracker.js

@@ -44,11 +44,11 @@ proto.toProjection = function toProjection() {
 	var last = "",
 		needId = false;
 
-	for(var it in this.fields.sort()) {
+	Object.keys(this.fields).sort().forEach(function (it) {
 		if (it.slice(0,3) == "_id" && (it.length == 3 || it.charAt(3) == ".")) {
 			// _id and subfields are handled specially due in part to SERVER-7502
 			needId = true;
-			continue;
+			return;
 		}
 
 		if (last !== "" && it.slice(0, last.length) === last) {
@@ -57,12 +57,12 @@ proto.toProjection = function toProjection() {
 			// field, the parent wouldn't be fully included. This logic relies
 			// on on set iterators going in lexicographic order so that a string
 			// is always directly before of all fields it prefixes.
-			continue;
+			return;
 		}
 
 		last = it + ".";
 		proj[it] = 1;
-	}
+	});
 
 	if (needId)
 		proj._id = 1;
@@ -81,27 +81,27 @@ proto.toProjection = function toProjection() {
 proto.toParsedDeps = function toParsedDeps() {
 	var doc = {};
 
-	if(this.needWholeDocument || this.needTextScore) {
+	if (this.needWholeDocument || this.needTextScore) {
 		// can't use ParsedDeps in this case
 		// TODO: not sure what appropriate equivalent to boost::none is
 		return;
 	}
 
 	var last = "";
-	for(var it in this.fields.sort()) {
+	Object.keys(this.fields).sort().forEach(function (it) {
 		if (last !== "" && it.slice(0, last.length) === last) {
 			// we are including a parent of *it so we don't need to include this
 			// field explicitly. In fact, due to SERVER-6527 if we included this
 			// field, the parent wouldn't be fully included. This logic relies
 			// on on set iterators going in lexicographic order so that a string
 			// is always directly before of all fields it prefixes.
-			continue;
+			return;
 		}
 
 		last = it + ".";
 		// TODO: set nested field to true; i.e. a.b.c = true, not a = true
 		doc[it] = true;
-	}
+	});
 
 	return new ParsedDeps(doc);
 };

+ 1 - 1
test/lib/pipeline/DepsTracker.js

@@ -72,7 +72,7 @@ module.exports = {
 			"should be able to parse dependencies with subfields": function() {
 				var deps = new DepsTracker(),
 					expected = {"_fields":{"a.b":true}};
-				deps.fields = {'a.b':1};
+				deps.fields = {'a':1,'a.b':1};
 
 				assert.deepEqual(expected, deps.toParsedDeps());
 			}