From 11480fb7224d8d13f1ddd04a3c453fb598b29760 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Mon, 15 Jul 2019 14:31:33 -0700 Subject: [PATCH] Fix duplicate fetch in Visualize --- .../kibana/public/visualize/editor/editor.js | 16 +++++++++++----- 1 file changed, 11 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 6db6e2c9ad1c9..0cb705f94a0e0 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js @@ -406,7 +406,7 @@ function VisEditor( const filterUpdateSubscription = subscribeWithScope($scope, queryFilter.getUpdates$(), { next: () => { $scope.filters = queryFilter.getFilters(); - $scope.fetch(); + $scope.globalFilters = queryFilter.getGlobalFilters(); } }); @@ -415,7 +415,6 @@ function VisEditor( $state.save(); savedVis.searchSource.setField('query', $state.query); savedVis.searchSource.setField('filter', $state.filters); - $scope.globalFilters = queryFilter.getGlobalFilters(); $scope.vis.forceReload(); }; @@ -441,9 +440,16 @@ function VisEditor( } $scope.updateQueryAndFetch = function ({ query, dateRange }) { - timefilter.setTime(dateRange); - $state.query = query; - $scope.fetch(); + const isUpdate = ( + (query && !_.isEqual(query, $state.query)) || + (dateRange && !_.isEqual(dateRange, $scope.timeRange)) + ); + + if (query && !_.isEqual(query, $state.query)) $state.query = query; + if (dateRange && !_.isEqual(dateRange, $scope.timeRange)) timefilter.setTime(dateRange); + + // If nothing has changed, trigger the fetch manually, otherwise it will happen as a result of the changes + if (!isUpdate) $scope.fetch(); }; $scope.onRefreshChange = function ({ isPaused, refreshInterval }) {