diff --git a/.changeset/heatmap-filters-skip-column-refetch.md b/.changeset/heatmap-filters-skip-column-refetch.md new file mode 100644 index 000000000..34fe594aa --- /dev/null +++ b/.changeset/heatmap-filters-skip-column-refetch.md @@ -0,0 +1,5 @@ +--- +'@hyperdx/app': patch +--- + +fix: Don't refetch the trace heatmap or filter values when a table column is added or removed diff --git a/packages/app/src/DBSearchPage.tsx b/packages/app/src/DBSearchPage.tsx index e75e0bde8..f42b47e41 100644 --- a/packages/app/src/DBSearchPage.tsx +++ b/packages/app/src/DBSearchPage.tsx @@ -2160,12 +2160,29 @@ function DBSearchPageContent() { ? searchedSource : null; + const histogramGroupBy = resolveSearchGroupBy(groupByParam, searchedSource); + + // The histogram, trace heatmap and filter queries don't select the table's + // columns, so they only take the aliases they use. The rest would refetch + // them whenever a column is added or removed. Everything but the table's + // select and sort can reference an alias, including the body, timestamp and + // sample-weight expressions. + const referencedAliasWith = useMemo( + () => + chartConfig == null + ? undefined + : getReferencedWithClauses(aliasWith, [ + JSON.stringify({ ...chartConfig, select: '', orderBy: '' }), + histogramGroupBy ?? '', + ]), + [chartConfig, aliasWith, histogramGroupBy], + ); + const histogramTimeChartConfig = useMemo(() => { if (chartConfig == null) { return undefined; } - const groupBy = resolveSearchGroupBy(groupByParam, searchedSource); return { ...chartConfig, select: [ @@ -2179,12 +2196,7 @@ function DBSearchPageContent() { granularity: 'auto', dateRange: searchedTimeRange, displayType: DisplayType.StackedBar, - // Everything but the table's select and sort can reference an alias, - // including the body, timestamp and sample-weight expressions. - with: getReferencedWithClauses(aliasWith, [ - JSON.stringify({ ...chartConfig, select: '', orderBy: '' }), - groupBy ?? '', - ]), + with: referencedAliasWith, // Preserve the original table select string for "View Events" links. // convertToTimeChartConfig drops it from the query key. eventTableSelect: searchedConfig.select ?? undefined, @@ -2197,15 +2209,14 @@ function DBSearchPageContent() { alignDateRangeToGranularity: false, // Make sure the end date is inclusive so that the histogram and table counts match dateRangeEndInclusive: true, - groupBy, + groupBy: histogramGroupBy, } satisfies BuilderChartConfigWithDateRange; }, [ chartConfig, - searchedSource, - aliasWith, + referencedAliasWith, searchedTimeRange, searchedConfig.select, - groupByParam, + histogramGroupBy, ]); // The default severity/status grouping reads without a legend. @@ -2246,9 +2257,9 @@ function DBSearchPageContent() { ...chartConfig, orderBy: undefined, dateRange: searchedTimeRange, - with: aliasWith, + with: referencedAliasWith, } satisfies BuilderChartConfigWithDateRange), - [chartConfig, searchedTimeRange, aliasWith], + [chartConfig, searchedTimeRange, referencedAliasWith], ); // While the heatmap shows, live tail stays off as in delta and pattern modes: @@ -2329,10 +2340,13 @@ function DBSearchPageContent() { ); const filtersChartConfig = useMemo(() => { + // The filter queries set their own select, so the table's would only + // change their query keys. const overrides = { + select: '', orderBy: undefined, dateRange: searchedTimeRange, - with: aliasWith, + with: referencedAliasWith, } as const; return chartConfig ? { @@ -2347,10 +2361,9 @@ function DBSearchPageContent() { tableName: '', }, where: '', - select: '', ...overrides, }; - }, [chartConfig, searchedTimeRange, aliasWith]); + }, [chartConfig, searchedTimeRange, referencedAliasWith]); const openNewSourceModal = useCallback(() => { setNewSourceModalOpened(true);