-
Notifications
You must be signed in to change notification settings - Fork 968
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: reduce min / max loops #7607
base: master
Are you sure you want to change the base?
Conversation
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.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
const datetime = new Date(datetimeString); | ||
const { value: price } = convertPrice(value.price?.value, value.price?.currency); | ||
|
||
chartData.push({ | ||
datetime, | ||
const chartData = Object.entries(zoneData.zoneStates).map( | ||
([datetimeString, value]) => ({ | ||
datetime: new Date(datetimeString), | ||
layerData: { | ||
price: price ?? Number.NaN, | ||
price: | ||
convertPrice(value.price?.value, value.price?.currency).value ?? Number.NaN, | ||
}, | ||
meta: value, | ||
}); | ||
} | ||
}) | ||
); |
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.
Doesn't this change the output from price: 123
to price: { value: 123 }
? 🤔
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'll have to double check again, was a while ago I wrote it but the charts work just fine in the preview.
Issue
We are mapping over some objects twice to calculate the min, and then once again for the max value.
We can simplify this to one loop/map and then pass the mapped values to both functions.
Description
Reduces the looping and uses more functional syntax.
Double check
pnpx prettier@2 --write .
andpoetry run format
in the top level directory to format my changes.