Document $__undoReset
performance on deeply nested documents
#15255
Labels
Milestone
$__undoReset
performance on deeply nested documents
#15255
Prerequisites
Mongoose version
8.10.0
Node.js version
v18.19.0
MongoDB server version
8.0.4
Typescript version (if applicable)
No response
Description
When updating a document fails due to a version error, we've noticed that the method
$__undoReset
is called for the document. However, we found that it gets called recursively many more times than needed, because it's callinggetAllSubdocs
(which should get all subdocs on the current document regardless of how deeply nested they are) recursively, which causes the undoReset function to be called a lot.On our repro, adding a
console.count
to the header of the$__undoReset
function, the function gets called around 700k times, taking a second or so to execute. However, the sample document only contains around 1024 subdocuments.Steps to Reproduce
Expected Behavior
This should be way faster, because the undoReset should only get called once per subdocument. We've made a quick workaround plugin that overrides the original undoReset method and makes it not recursive, since getAllSubdocs is already recursive:
The text was updated successfully, but these errors were encountered: