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
SQL Datasources: Prevent Call Stack Overflows with Large Numbers of Values for Variable #64937
Conversation
Hello @codeincarnate!
Please, if the current pull request addresses a bug fix, label it with the |
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.
LGTM!
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.
Good catch! LGTM.
text: v, | ||
})) | ||
); | ||
frame.fields.flatMap((f) => f.values.toArray()).map((v) => values.push({ text: v })); |
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.
Just a question, is there a reason you're using a map()
here instead of a forEach()
or just for of
loop? Since you're not returning anything, would a forEach() make more sense?
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.
@baldm0mma I refactored this to simple for of loops. WDYT?
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 personally think it's more readable, and therefore more maintainable; big fan!
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.
LGTM!
describe('transformMetricFindResponse function', () => { | ||
it('should handle big arrays', () => { | ||
const responseParser = new ResponseParser(); | ||
const stringValues = new Array(150000); |
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.
Great idea on adding this test! Do we need to import fill()
from lodash
here? I believe we can accomplish the same thing with the native JS fill()
function -> new Array(150_000).fill('a');
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.
TIL 😱
LGTM! |
…bers of Values for Variable (#65182) SQL Datasources: Prevent Call Stack Overflows with Large Numbers of Values for Variable (#64937) * Push values with every map call to avoid hitting the maximum call stack size. * Add test and refactor to for of * Use native fill instead of lodash --------- Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> (cherry picked from commit bf687ff) Co-authored-by: Kyle Cunningham <codeincarnate@users.noreply.github.com>
…alues for Variable (#64937) * Push values with every map call to avoid hitting the maximum call stack size. * Add test and refactor to for of * Use native fill instead of lodash --------- Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This PR prevents call stack overflows in SQL datasources. This can happen when getting variable values because of a spread operator (which has a map used inside) causing a large number of function calls to be added to the stack. This PR removes the spread operator and instead adds variable values directly from the call to
map
.