From a618a3e5330a130bff25cef14f2070af07e48c57 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 24 Jul 2019 15:45:07 -0700 Subject: [PATCH] Don't refetch when disabled filters change --- .../kibana/public/visualize/editor/editor.js | 8 +++++++- .../visualize/editor/visualization_editor.js | 15 +++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js index 0cb705f94a0e..d922a30ba2d2 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js @@ -405,8 +405,14 @@ function VisEditor( // update the searchSource when filters update const filterUpdateSubscription = subscribeWithScope($scope, queryFilter.getUpdates$(), { next: () => { - $scope.filters = queryFilter.getFilters(); + const filters = queryFilter.getFilters(); + const isFetchRequired = !_.isEqual( + (filters || []).filter(filter => !filter.meta.disabled), + ($scope.filters || []).filter(filter => !filter.meta.disabled), + ); + $scope.filters = filters; $scope.globalFilters = queryFilter.getGlobalFilters(); + if (isFetchRequired) $scope.fetch(); } }); diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/visualization_editor.js b/src/legacy/core_plugins/kibana/public/visualize/editor/visualization_editor.js index a2ed44df2f5b..e2902edbc14f 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/visualization_editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/editor/visualization_editor.js @@ -17,7 +17,7 @@ * under the License. */ -import { debounce } from 'lodash'; +import { debounce, isEqual } from 'lodash'; import { uiModules } from 'ui/modules'; import 'angular-sanitize'; import { VisEditorTypesRegistryProvider } from 'ui/registry/vis_editor_types'; @@ -59,9 +59,16 @@ uiModules editor.destroy(); }); - $scope.$watchGroup(['timeRange', 'filters'], debounce(() => { - $scope.renderFunction(); - }, 100)); + const debouncedRender = debounce($scope.renderFunction, 100); + $scope.$watch('timeRange', debouncedRender); + $scope.$watch('filters', filters => { + if (!isEqual( + (filters || []).filter(filter => !filter.meta.disabled), + ($scope.filters || []).filter(filter => !filter.meta.disabled), + )) { + debouncedRender(); + } + }); } }; });