From 31c888ea8e5de89483cc98ce628046202feb7515 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Fri, 30 Aug 2019 07:03:51 +0300 Subject: [PATCH] Dashboard: when updating parameters, run only relevant queries (#3804) * refresh only affected queries in dashboard when parameters are changed * rename pendingParameters to updatedParameters * select which widgets to update according to their mapping as a dashboard-level parameter * use lodash's include --- client/app/components/Parameters.jsx | 3 ++- client/app/components/dashboards/widget.html | 2 +- client/app/components/dashboards/widget.js | 2 ++ client/app/pages/dashboards/dashboard.js | 16 ++++++++++++---- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client/app/components/Parameters.jsx b/client/app/components/Parameters.jsx index afbd2b86fc..285b6a6237 100644 --- a/client/app/components/Parameters.jsx +++ b/client/app/components/Parameters.jsx @@ -111,8 +111,9 @@ export class Parameters extends React.Component { applyChanges = () => { const { onValuesChange, disableUrlUpdate } = this.props; this.setState(({ parameters }) => { + const parametersWithPendingValues = parameters.filter(p => p.hasPendingValue); forEach(parameters, p => p.applyPendingValue()); - onValuesChange(); + onValuesChange(parametersWithPendingValues); if (!disableUrlUpdate) { updateUrl(parameters); } diff --git a/client/app/components/dashboards/widget.html b/client/app/components/dashboards/widget.html index a9f6ff7f2d..5154b4a308 100644 --- a/client/app/components/dashboards/widget.html +++ b/client/app/components/dashboards/widget.html @@ -44,7 +44,7 @@
- +
diff --git a/client/app/components/dashboards/widget.js b/client/app/components/dashboards/widget.js index 95b9d6380d..b51d427f91 100644 --- a/client/app/components/dashboards/widget.js +++ b/client/app/components/dashboards/widget.js @@ -92,6 +92,8 @@ function DashboardWidgetCtrl($scope, $location, $uibModal, $window, $rootScope, return this.widget.load(refresh, maxAge); }; + this.forceRefresh = () => this.load(true); + this.refresh = (buttonId) => { this.refreshClickButtonId = buttonId; this.load(true).finally(() => { diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index f283c3594b..e2ed937b50 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -137,8 +137,16 @@ function DashboardCtrl( this.extractGlobalParameters(); }); - const collectFilters = (dashboard, forceRefresh) => { - const queryResultPromises = _.compact(this.dashboard.widgets.map((widget) => { + const collectFilters = (dashboard, forceRefresh, updatedParameters = []) => { + const affectedWidgets = updatedParameters.length > 0 ? this.dashboard.widgets.filter( + widget => Object.values(widget.getParameterMappings()).filter( + ({ type }) => type === 'dashboard-level', + ).some( + ({ mapTo }) => _.includes(updatedParameters.map(p => p.name), mapTo), + ), + ) : this.dashboard.widgets; + + const queryResultPromises = _.compact(affectedWidgets.map((widget) => { widget.getParametersDefs(); // Force widget to read parameters values from URL return widget.load(forceRefresh); })); @@ -202,9 +210,9 @@ function DashboardCtrl( this.loadDashboard(); - this.refreshDashboard = () => { + this.refreshDashboard = (parameters) => { this.refreshInProgress = true; - collectFilters(this.dashboard, true).finally(() => { + collectFilters(this.dashboard, true, parameters).finally(() => { this.refreshInProgress = false; }); };