-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11414 from Uzlopak/perf-invalid-path
perf: improve validation sync and async by replacing forEach with classic for loops
- Loading branch information
Showing
2 changed files
with
16 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2853,19 +2853,21 @@ Document.prototype.validateSync = function(pathsToValidate, options) { | |
} | ||
const validating = {}; | ||
|
||
paths.forEach(function(path) { | ||
for (let i = 0, len = paths.length; i < len; ++i) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vkarpov15
Author
Collaborator
|
||
const path = paths[i]; | ||
|
||
if (validating[path]) { | ||
return; | ||
continue; | ||
} | ||
|
||
validating[path] = true; | ||
|
||
const p = _this.$__schema.path(path); | ||
if (!p) { | ||
return; | ||
continue; | ||
} | ||
if (!_this.$isValid(path)) { | ||
return; | ||
continue; | ||
} | ||
|
||
const val = _this.$__getValue(path); | ||
|
@@ -2879,11 +2881,11 @@ Document.prototype.validateSync = function(pathsToValidate, options) { | |
p.$isArraySubdocument || | ||
p.$isMongooseDocumentArray; | ||
if (isSubdoc && err instanceof ValidationError) { | ||
return; | ||
continue; | ||
} | ||
_this.invalidate(path, err, undefined, true); | ||
} | ||
}); | ||
} | ||
|
||
const err = _this.$__.validationError; | ||
_this.$__.validationError = undefined; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Uzlopak
I've always found that
for (const path of paths) { ... }
more readable.Do you happen to know if there is a performance advantage of using for loop with incrementing a variable over for-of?