Skip to content
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

Refresh plan statistics after re-run the query #1455

Merged
merged 2 commits into from
Jul 5, 2021

Conversation

alexabidri
Copy link
Contributor

@alexabidri alexabidri commented Jun 28, 2021

Problem has been explained here -> #1454

The issue is to refresh the state of the react component that display the plan stats at the bottom of the window

Here is a little video of the fix, sorry for the bad quality, you can see the stats are updating at the bottom of the query window
ezgif com-gif-maker (1)

Copy link
Contributor

@OskarDamkjaer OskarDamkjaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for both reporting and fixing this issue! We're already aware of it and I put a fix up in #1451, but I'm happy to include your fix instead.

The bug snuck in as we didn't want to run bolt.extractPlan unless it was needed, as you noted this was done in a way so that only ever ran once. With your suggested fix, it'll be recalculated every time the component re-renders, which would be less performant but not an issue for such a simple component. However it seems to me that we no longer need the componentDidMount and the componentDidUpdate lifecycle methods when we have derivedStateFromprops?

Also for the tests to run properly and for us to be able to merge your change you'll need to sign our CLA.

@OskarDamkjaer
Copy link
Contributor

To prevent the performance hit, we could add memoize-one with a custom equality function using the check from shouldComponentUpdate. What do you think @alexabidri?

@alexabidri alexabidri force-pushed the refresh-plan-stats branch from b930092 to c2c1ac9 Compare July 3, 2021 02:23
@alexabidri
Copy link
Contributor Author

alexabidri commented Jul 3, 2021

@OskarDamkjaer Thanks for your comment and happy to consider my fix!
Will take into account and re-test the flow 👍
Also, I have sent the proper CLA but it still doesnt pass the CI

@alexabidri alexabidri force-pushed the refresh-plan-stats branch from c2c1ac9 to 00ebe57 Compare July 3, 2021 03:20
@OskarDamkjaer
Copy link
Contributor

There's a manual step to whitelist contributors, didn't see your email but I've added you now!

I had a look at your code, and the memorization is not quite there yet, it'll still run extractPlan when it's not needed. For it to only rerun when we the summary changes we'll need to do something like this (custom equality function):

const extractMemoizedPlan = memoize(
  result => bolt.extractPlan(result, true),
  (a: any, b: any) => deepEquals(a[0]?.result?.summary, b[0]?.result?.summary)
)

Reading your changes I found we also no longer need to keep the plan in state, so we could just do something like this in the render():

const { result } = this.props
if (!result || !result.summary) return null

const plan = extractMemoizedPlan(result)
if (!plan) return null

return (<StyledOneRowStatsBar>//... and so on

Are you happy to update the memo function?

@alexabidri
Copy link
Contributor Author

You are right, will be even better indeed. I took your feedback into account and also passed the component as a pure component for readability and understandability. Thanks

@OskarDamkjaer
Copy link
Contributor

Nice cleanup, thanks a lot! I'll merge when the tests come back green 🎉

@OskarDamkjaer OskarDamkjaer self-requested a review July 5, 2021 14:08
Copy link
Contributor

@OskarDamkjaer OskarDamkjaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! 💯

@OskarDamkjaer OskarDamkjaer merged commit 6910b0a into neo4j:master Jul 5, 2021
@OskarDamkjaer
Copy link
Contributor

OskarDamkjaer commented Jul 5, 2021

If you want to use your changes before they're officially released in browser 4.3.2 (some time in august), master is deployed to https://browser-canary.graphapp.io/ a few hours after merging. So you should be able to use it from there tomorrow (not guaranteed to be 100% stable though 😅 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants