From a209fe8d7d7d1e27bb9b80475ea2821a9202e823 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Wed, 9 Oct 2024 18:46:31 +0200 Subject: [PATCH] [Lens][ES|QL] Do not refetch the attributes if the query hasn't changed (#195196) ## Summary When a user is creating a Lens ES|QL chart we run the suggestions api even if the query hasn't changed. This PR adds a guard to avoid refetching the attributes when the query hasn't changed at all. --- .../shared/edit_on_the_fly/lens_configuration_flyout.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.tsx b/x-pack/plugins/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.tsx index ecc392a7e56b7..fd0407513f869 100644 --- a/x-pack/plugins/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.tsx +++ b/x-pack/plugins/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.tsx @@ -337,6 +337,7 @@ export function LensEditConfigurationFlyout({ setErrors([]); updateSuggestion?.(attrs); } + prevQuery.current = q; setIsVisualizationLoading(false); }, [ @@ -481,7 +482,6 @@ export function LensEditConfigurationFlyout({ query={query} onTextLangQueryChange={(q) => { setQuery(q); - prevQuery.current = q; }} detectedTimestamp={adHocDataViews?.[0]?.timeFieldName} hideTimeFilterInfo={hideTimeFilterInfo} @@ -497,7 +497,8 @@ export function LensEditConfigurationFlyout({ editorIsInline hideRunQueryText onTextLangQuerySubmit={async (q, a) => { - if (q) { + // do not run the suggestions if the query is the same as the previous one + if (q && !isEqual(q, prevQuery.current)) { setIsVisualizationLoading(true); await runQuery(q, a); }