-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Discover] Fix performance regression in sidebar #109999
Changes from all commits
77f1676
7ec29cd
bafa77e
b0e03a6
3c15e62
ed8868e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,7 +358,36 @@ function DiscoverFieldComponent({ | |
</EuiPopoverTitle> | ||
); | ||
|
||
const details = getDetails(field); | ||
const renderPopover = () => { | ||
const details = getDetails(field); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. making sure |
||
return ( | ||
<> | ||
<DiscoverFieldDetails | ||
indexPattern={indexPattern} | ||
field={field} | ||
details={details} | ||
onAddFilter={onAddFilter} | ||
/> | ||
{multiFields && ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<MultiFields | ||
multiFields={multiFields} | ||
alwaysShowActionButton={alwaysShowActionButton} | ||
toggleDisplay={toggleDisplay} | ||
/> | ||
</> | ||
)} | ||
<DiscoverFieldVisualize | ||
field={field} | ||
indexPattern={indexPattern} | ||
multiFields={rawMultiFields} | ||
trackUiMetric={trackUiMetric} | ||
details={details} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<EuiPopover | ||
|
@@ -396,33 +425,7 @@ function DiscoverFieldComponent({ | |
})} | ||
</h5> | ||
</EuiTitle> | ||
{infoIsOpen && ( | ||
<> | ||
<DiscoverFieldDetails | ||
indexPattern={indexPattern} | ||
field={field} | ||
details={details} | ||
onAddFilter={onAddFilter} | ||
/> | ||
{multiFields && ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<MultiFields | ||
multiFields={multiFields} | ||
alwaysShowActionButton={alwaysShowActionButton} | ||
toggleDisplay={toggleDisplay} | ||
/> | ||
</> | ||
)} | ||
<DiscoverFieldVisualize | ||
field={field} | ||
indexPattern={indexPattern} | ||
multiFields={rawMultiFields} | ||
trackUiMetric={trackUiMetric} | ||
details={details} | ||
/> | ||
</> | ||
)} | ||
{infoIsOpen && renderPopover()} | ||
</EuiPopover> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,17 +120,22 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps) | |
* needed for merging new with old field counts, high likely legacy, but kept this behavior | ||
* because not 100% sure in this case | ||
*/ | ||
const fieldCounts = useRef<Record<string, number>>( | ||
calcFieldCounts({}, props.documents$.getValue().result, props.selectedIndexPattern) | ||
); | ||
const fieldCounts = useRef<Record<string, number> | null>(null); | ||
if (fieldCounts.current === null) { | ||
fieldCounts.current = calcFieldCounts( | ||
{}, | ||
props.documents$.getValue().result, | ||
props.selectedIndexPattern | ||
); | ||
} | ||
Comment on lines
+124
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be moved to useEffect, before subscription, which should initialized after mounting |
||
|
||
const [documentState, setDocumentState] = useState(props.documents$.getValue()); | ||
useEffect(() => { | ||
const subscription = props.documents$.subscribe((next) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (next.fetchStatus !== documentState.fetchStatus) { | ||
if (next.result) { | ||
fieldCounts.current = calcFieldCounts( | ||
next.result.length ? fieldCounts.current : {}, | ||
next.result.length && fieldCounts.current ? fieldCounts.current : {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still having trouble understanding this logic. we're calculating fieldCounts, passing in the value that we got as a result of passing in the previous result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it's like it behaved for a long time, didn't change, but I think it should be in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this logic needs some revisiting, but after testing I don't think it's broken. Let's see if we can do some cleanup here in a follow-up PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 wanna add an issue for that? |
||
next.result, | ||
props.selectedIndexPattern! | ||
); | ||
|
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.
less error messages when executing the test