Repository navigation
fix: prevent unnecessary histogram rerender #3749
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
Changes from all commits
cd22558
7398144
b5312ca
61f58e2
341c7d0
39998be
69f52c0
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| '@hyperdx/common-utils': patch | ||
| --- | ||
|
|
||
| fix: Don't refetch the search histogram when a table column is added or removed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata'; | |
| import { buildSearchChartConfig } from '@hyperdx/common-utils/dist/core/searchChartConfig'; | ||
| import { | ||
| aliasMapToWithClauses, | ||
| getReferencedWithClauses, | ||
| isBrowser, | ||
| splitAndTrimWithBracket, | ||
| } from '@hyperdx/common-utils/dist/core/utils'; | ||
|
|
@@ -1304,13 +1305,22 @@ function DBSearchPageContent() { | |
|
|
||
| const [displayedTimeInputValue, setDisplayedTimeInputValue] = | ||
| useState('Live Tail'); | ||
| // The last time input the time query wrote, i.e. the applied range. User | ||
| // typing goes through setDisplayedTimeInputValue, so it differs once edited. | ||
| const [appliedTimeInputValue, setAppliedTimeInputValue] = | ||
| useState('Live Tail'); | ||
| const setAppliedTimeInput = useCallback((value: string) => { | ||
| setDisplayedTimeInputValue(value); | ||
| setAppliedTimeInputValue(value); | ||
| }, []); | ||
| const isTimeInputEdited = displayedTimeInputValue !== appliedTimeInputValue; | ||
|
|
||
| const { isReady, searchedTimeRange, onSearch, onTimeRangeSelect } = | ||
| useNewTimeQuery({ | ||
| initialDisplayValue: 'Live Tail', | ||
| initialTimeRange: defaultTimeRange, | ||
| showRelativeInterval: isLive ?? true, | ||
| setDisplayedTimeInputValue, | ||
| setDisplayedTimeInputValue: setAppliedTimeInput, | ||
| updateInput: !isLive, | ||
| }); | ||
|
|
||
|
|
@@ -1420,8 +1430,13 @@ function DBSearchPageContent() { | |
| // completes "Explore your data". An explicit arg, not a shared ref, so | ||
| // concurrent submits can't consume each other's suppression. | ||
| const onSubmit = useCallback( | ||
| ({ recordExploration = true }: { recordExploration?: boolean } = {}) => { | ||
| onSearch(displayedTimeInputValue); | ||
| ({ | ||
| recordExploration = true, | ||
| resolveTimeRange = true, | ||
| }: { recordExploration?: boolean; resolveTimeRange?: boolean } = {}) => { | ||
| if (resolveTimeRange) { | ||
| onSearch(displayedTimeInputValue); | ||
| } | ||
| handleSubmit( | ||
| ({ select, where, whereLanguage, source, filters, orderBy }) => { | ||
| setSearchedConfig({ | ||
|
|
@@ -1858,12 +1873,15 @@ function DBSearchPageContent() { | |
| parseAsInteger.withDefault(DEFAULT_REFRESH_FREQUENCY), | ||
| ); | ||
|
|
||
| const updateRelativeTimeInputValue = useCallback((interval: number) => { | ||
| const label = getRelativeTimeOptionLabel(interval); | ||
| if (label) { | ||
| setDisplayedTimeInputValue(label); | ||
| } | ||
| }, []); | ||
| const updateRelativeTimeInputValue = useCallback( | ||
| (interval: number) => { | ||
| const label = getRelativeTimeOptionLabel(interval); | ||
| if (label) { | ||
| setAppliedTimeInput(label); | ||
| } | ||
| }, | ||
| [setAppliedTimeInput], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (isReady && isLive) { | ||
|
|
@@ -1995,7 +2013,11 @@ function DBSearchPageContent() { | |
| setValue('orderBy', nextOrderBy); | ||
| } | ||
| } | ||
| onSubmit(); | ||
| // Keep the current time range unless the user typed a new one: | ||
| // re-resolving a relative range would refetch the histogram for a | ||
| // column change. Live tail refetches on every tick anyway, so it always | ||
| // re-resolves. | ||
| onSubmit({ resolveTimeRange: !!isLive || isTimeInputEdited }); | ||
| }, | ||
| [ | ||
| displayedColumns, | ||
|
|
@@ -2004,6 +2026,8 @@ function DBSearchPageContent() { | |
| getValues, | ||
| defaultSearchConfig.orderBy, | ||
| onSubmit, | ||
| isLive, | ||
| isTimeInputEdited, | ||
| ], | ||
| ); | ||
|
|
||
|
|
@@ -2141,6 +2165,7 @@ function DBSearchPageContent() { | |
| return undefined; | ||
| } | ||
|
|
||
| const groupBy = resolveSearchGroupBy(groupByParam, searchedSource); | ||
| return { | ||
| ...chartConfig, | ||
| select: [ | ||
|
|
@@ -2154,8 +2179,14 @@ function DBSearchPageContent() { | |
| granularity: 'auto', | ||
| dateRange: searchedTimeRange, | ||
| displayType: DisplayType.StackedBar, | ||
| with: aliasWith, | ||
| // Preserve the original table select string for "View Events" links | ||
| // Everything but the table's select and sort can reference an alias, | ||
| // including the body, timestamp and sample-weight expressions. | ||
| with: getReferencedWithClauses(aliasWith, [ | ||
|
knudtty marked this conversation as resolved.
Resolved
|
||
| JSON.stringify({ ...chartConfig, select: '', orderBy: '' }), | ||
|
Contributor
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. 🟡 P2 — Alias matching runs over the whole config JSON, so many aliases are always kept and the histogram still refetches
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| groupBy ?? '', | ||
| ]), | ||
| // Preserve the original table select string for "View Events" links. | ||
| // convertToTimeChartConfig drops it from the query key. | ||
| eventTableSelect: searchedConfig.select ?? undefined, | ||
| // Never align to granularity boundaries on the search page: the histogram | ||
| // and total count must reflect the user's exact selected range so they | ||
|
|
@@ -2166,7 +2197,7 @@ function DBSearchPageContent() { | |
| alignDateRangeToGranularity: false, | ||
| // Make sure the end date is inclusive so that the histogram and table counts match | ||
| dateRangeEndInclusive: true, | ||
| groupBy: resolveSearchGroupBy(groupByParam, searchedSource), | ||
| groupBy, | ||
| } satisfies BuilderChartConfigWithDateRange; | ||
| }, [ | ||
| chartConfig, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.