-
Notifications
You must be signed in to change notification settings - Fork 11.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] cache resolved data element options #6579
Conversation
src/helpers/helpers.options.js
Outdated
@@ -114,24 +114,32 @@ module.exports = { | |||
* @param {object} [context] - If defined and the current value is a function, the value | |||
* is called with `context` as first argument and the result becomes the new input. | |||
* @param {number} [index] - If defined and the current value is an array, the value | |||
* @param {object} [info] - object to return information about resolution in |
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.
I think I'd initialize info.cacheable
to true
in this method so that if you call resolve
outside of _resolveDataElementOptions
then info
contains a usable value. Then in _resolveDataElementOptions
you can check if (info.cacheable && !custom)
instead of if (info.cacheable)
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.
It would have to be something like
if (info && info.cacheable === undefined) {
info.cacheable = true;
}
because resolve
is called in a loop. But I think its not needed. You'd need to provide the info object anyway, so not a biggie to provide initial value too.
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.
In other words, I like to keep the initialization (and any related if's) out of loop
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.
Maybe just document it then?
* @param {boolean} [info.cacheable] - Should be initialized to true. Will be updated by this method.
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.
This looks good! Definitely less code than my version!
I had opened my PR previously and you left a comment that I didn't understand. I was going to follow up with you to clarify, but now I understand :-) Thanks so much!
Was about to merge but I thought of this case:
Or am I missing something here? |
DatasetController does |
Right, just wanted to make sure that case was tested |
* [perf] cache resolved data element options * Address review comments * Move uninitialized variables, update comments
Alternative approach that came to mind while taking a look at #6574
Closes #6382