-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
perf: make a few micro-optimizations to help speed up findOne() #15022
Conversation
lib/query.js
Outdated
@@ -2291,9 +2293,9 @@ Query.prototype.mongooseOptions = function(v) { | |||
|
|||
Query.prototype._castConditions = function() { | |||
let sanitizeFilterOpt = undefined; | |||
if (this.model != null && utils.hasUserDefinedProperty(this.model.db.options, 'sanitizeFilter')) { | |||
if (this.model != null && this.model.db.options?.sanitizeFilter != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also be shortened to:
if (this.model != null && this.model.db.options?.sanitizeFilter != null) { | |
if (this.model?.db.options?.sanitizeFilter != null) { |
lib/query.js
Outdated
sanitizeFilterOpt = this.model.db.options.sanitizeFilter; | ||
} else if (this.model != null && utils.hasUserDefinedProperty(this.model.base.options, 'sanitizeFilter')) { | ||
} else if (this.model != null && this.model.base.options?.sanitizeFilter != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
} else if (this.model != null && this.model.base.options?.sanitizeFilter != null) { | |
} else if (this.model?.base.options?.sanitizeFilter != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor suggestions, otherwise LGTM.
@@ -2248,6 +2247,9 @@ Query.prototype.error = function error(err) { | |||
*/ | |||
|
|||
Query.prototype._unsetCastError = function _unsetCastError() { | |||
if (this._error == null) { | |||
return; | |||
} | |||
if (this._error != null && !(this._error instanceof CastError)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vkarpov15 Since you already checked (this._error == null)
above, you can simplify the condition as below.
if (!(this._error instanceof CastError)) {}
Re: #14906
Summary
Some small improvements that maybe give us an extra 1-2% on performance. Not huge, but a step in the right direction. I'm still debugging to see where we can find some extra perf.
Examples