Ver Fonte

feat(templating): fixed issue with template variables set to reload on dashboard load being issued multiple times, fixes #5637

Torkel Ödegaard há 9 anos atrás
pai
commit
0de0f4d014
1 ficheiros alterados com 10 adições e 8 exclusões
  1. 10 8
      public/app/features/templating/templateValuesSrv.js

+ 10 - 8
public/app/features/templating/templateValuesSrv.js

@@ -10,6 +10,7 @@ function (angular, _, kbn) {
 
 
   module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv) {
   module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv) {
     var self = this;
     var self = this;
+    this.variableLock = {};
 
 
     function getNoneOption() { return { text: 'None', value: '', isNone: true }; }
     function getNoneOption() { return { text: 'None', value: '', isNone: true }; }
 
 
@@ -90,6 +91,8 @@ function (angular, _, kbn) {
         } else {
         } else {
           lock.resolve();
           lock.resolve();
         }
         }
+      }).finally(function() {
+        delete self.variableLock[variable.name];
       });
       });
     };
     };
 
 
@@ -124,7 +127,7 @@ function (angular, _, kbn) {
       templateSrv.setGrafanaVariable('$__auto_interval', interval);
       templateSrv.setGrafanaVariable('$__auto_interval', interval);
     };
     };
 
 
-    this.setVariableValue = function(variable, option, initPhase) {
+    this.setVariableValue = function(variable, option) {
       variable.current = angular.copy(option);
       variable.current = angular.copy(option);
 
 
       if (_.isArray(variable.current.text)) {
       if (_.isArray(variable.current.text)) {
@@ -134,13 +137,7 @@ function (angular, _, kbn) {
       self.selectOptionsForCurrentValue(variable);
       self.selectOptionsForCurrentValue(variable);
       templateSrv.updateTemplateData();
       templateSrv.updateTemplateData();
 
 
-      // on first load, variable loading is ordered to ensure
-      // that parents are updated before children.
-      if (initPhase) {
-        return $q.when();
-      }
-
-      return self.updateOptionsInChildVariables(variable);
+      return this.updateOptionsInChildVariables(variable);
     };
     };
 
 
     this.variableUpdated = function(variable) {
     this.variableUpdated = function(variable) {
@@ -149,6 +146,11 @@ function (angular, _, kbn) {
     };
     };
 
 
     this.updateOptionsInChildVariables = function(updatedVariable) {
     this.updateOptionsInChildVariables = function(updatedVariable) {
+      // if there is a variable lock ignore cascading update because we are in a boot up scenario
+      if (self.variableLock[updatedVariable.name]) {
+        return $q.when();
+      }
+
       var promises = _.map(self.variables, function(otherVariable) {
       var promises = _.map(self.variables, function(otherVariable) {
         if (otherVariable === updatedVariable) {
         if (otherVariable === updatedVariable) {
           return;
           return;