-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Observability overview] Fix overview page duplicate requests #125204
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
Conversation
💚 Build SucceededMetrics [docs]Async chunks
To update your PR or re-run it, just comment with: cc @shahzad31 |
| const bucketSize = calculateBucketSize({ | ||
| start: absoluteTime.start, | ||
| end: absoluteTime.end, | ||
| }); | ||
|
|
||
| const bucketSizeValue = useMemo(() => { | ||
| if (bucketSize?.bucketSize) { | ||
| return { | ||
| bucketSize: bucketSize.bucketSize, | ||
| intervalString: bucketSize.intervalString, | ||
| }; | ||
| } | ||
| }, [bucketSize?.bucketSize, bucketSize?.intervalString]); | ||
|
|
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'm not sure that useMemo is the best option here. bucketSize and bucketSizeValue are exactly the same value and I don't think it reflects the intentions of what we want to achieve, which could lead to confusion and bugs in the future.
bucketSize should probably be part of the state of the component and we should only update it when absoluteTime.start or absoluteTime.end change, preventing unnecessary rerenders.
What do you think about something like this:
| const bucketSize = calculateBucketSize({ | |
| start: absoluteTime.start, | |
| end: absoluteTime.end, | |
| }); | |
| const bucketSizeValue = useMemo(() => { | |
| if (bucketSize?.bucketSize) { | |
| return { | |
| bucketSize: bucketSize.bucketSize, | |
| intervalString: bucketSize.intervalString, | |
| }; | |
| } | |
| }, [bucketSize?.bucketSize, bucketSize?.intervalString]); | |
| const [bucketSize, setBucketSize] = useState(undefined); | |
| useEffect(() => { | |
| const bucket = calculateBucketSize({ | |
| start: absoluteTime.start, | |
| end: absoluteTime.end, | |
| }); | |
| setBucketSize(bucket); | |
| }, [absoluteTime.start, absoluteTime.end]) | |
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 absolute time start and end changes whenever component re-renders , so can't use those in side effect
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 see... I wasn't expecting it 🙃
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Summary
Fixes #125200
Wrap bucketsize value in useMemo, since it was triggering unnecessary re-renders.