-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runValidators: true
for findOneAndUpdate
is orders of magnitude slower than save()
.
#8093
Comments
But I had similar results like yours and I do agree that the difference between Cheers! |
Same here, but even wierder: I have my schema like
and I also did a bit of profiling and found that all time is wasted inside this call: https://github.com/Automattic/mongoose/blob/master/lib/query.js#L3432, at which point, I also got a question, shouldn't it be wrapped into |
Quick investigation on @birdofpreyru 's point above... Looks like adding if() does help! Code change as below in query.js... Cheers! SG |
@birdofpreyru Can you add the if() line in your local repo and run the same test again with objects? Cheers! SG |
@sgatade yeap, I checked it, that without that call it works fast for me. But I also believe there is some performance bug inside the validation code: it is clearly so slow because it traverses all paths in a large JS document I put inside update, while in my case there is no need to touch it at all: in the Schema that field is declared as |
It was not an improvement of validation, it was because of the fix for |
…function logic Before this commit the `flatten(..)` function failed to deliver what it promised. Namely, it entered into Mixed paths of objects. Update validator, on its side, did not pass the casted doc schema into `flatten(..)`. If the casted doc contained a large Mixed field, all its paths were added into the list of updated paths. They were lated ignored by now removed check for schemaPath type, but performance was already hurt. This commit makes sure that inner sub-paths of Mixed paths are not included into the array of paths at all, thus no further checks of that are necessary, and the performance is restored. Fixes Automattic#8093
[#8093] Fixes performance of update validator, and flatten function logic
Do you want to request a feature or report a bug?
It can be considered a bug, or a performance issue.
What is the current behavior?
Using
Model#findOneAndUpdate(filter, update, { runValidators: true })
is orders of magnitude slower than usingModel#save()
on a relatively large document. ThatModel#findOneUpdate()
being slower thanModel#save()
is rather unexpected.If the current behavior is a bug, please provide the steps to reproduce.
Outputs:
What is the expected behavior?
Expected behaviour is that the
Model#findOneUpdate()
withrunValidators: true
option not to take any longer thanModel#save()
, let alone 22 times more in the provided example.I suspect the bottleneck may be here, but I haven't profiled where the time is spent most.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: