Browse Source

AMBARI-16139. Duplicate Dashboard metrics API calls should not be made in parallel. (Andrii Tkach via Jaimin)

Jaimin Jetly 9 years ago
parent
commit
1c29f1df06

+ 6 - 4
ambari-web/app/controllers/global/update_controller.js

@@ -422,11 +422,13 @@ App.UpdateController = Em.Controller.extend({
       var view = Em.View.views[_graph.id];
       var view = Em.View.views[_graph.id];
       if (view) {
       if (view) {
         existedGraphs.push(_graph);
         existedGraphs.push(_graph);
-        //console.log('updated graph', _graph.name);
-        view.loadData();
-        //if graph opened as modal popup update it to
-        if ($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
+        if (!view.get('isRequestRunning')) {
+          //console.log('updated graph', _graph.name);
           view.loadData();
           view.loadData();
+          //if graph opened as modal popup update it to
+          if ($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
+            view.loadData();
+          }
         }
         }
       }
       }
     });
     });

+ 9 - 0
ambari-web/app/views/common/chart/linear_time.js

@@ -185,6 +185,14 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
 
 
   _popupSelector: Em.computed.concat('', '_containerSelector', 'popupSuffix'),
   _popupSelector: Em.computed.concat('', '_containerSelector', 'popupSuffix'),
 
 
+  /**
+   * @type {boolean}
+   */
+  isRequestRunning: function() {
+    var requestsArrayName = this.get('isPopup') ? 'runningPopupRequests' : 'runningRequests';
+    return this.get(requestsArrayName).mapProperty('ajaxIndex').contains(this.get('ajaxIndex'));
+  }.property('runningPopupRequests', 'runningRequests'),
+
   didInsertElement: function () {
   didInsertElement: function () {
     var self = this;
     var self = this;
     this.setYAxisFormatter();
     this.setYAxisFormatter();
@@ -344,6 +352,7 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
             }));
             }));
           }
           }
         });
         });
+      if (request) request.ajaxIndex = this.get('ajaxIndex');
       this.get(requestsArrayName).push(request);
       this.get(requestsArrayName).push(request);
       return request;
       return request;
     }
     }

+ 52 - 1
ambari-web/test/views/common/chart/linear_time_test.js

@@ -21,8 +21,59 @@ require('views/common/chart/linear_time');
 var testHelpers = require('test/helpers');
 var testHelpers = require('test/helpers');
 
 
 describe('App.ChartLinearTimeView', function () {
 describe('App.ChartLinearTimeView', function () {
+  var chartLinearTimeView;
 
 
-  var chartLinearTimeView = App.ChartLinearTimeView.create({});
+  beforeEach(function() {
+    chartLinearTimeView = App.ChartLinearTimeView.create();
+  });
+
+  describe("#isRequestRunning", function () {
+
+    it("isPopup true, running request", function() {
+      chartLinearTimeView.setProperties({
+        isPopup: true,
+        runningPopupRequests: [{
+          ajaxIndex: 'req1'
+        }],
+        ajaxIndex: 'req1'
+      });
+      chartLinearTimeView.propertyDidChange('isRequestRunning');
+      expect(chartLinearTimeView.get('isRequestRunning')).to.be.true;
+    });
+
+    it("isPopup false, running request", function() {
+      chartLinearTimeView.setProperties({
+        isPopup: false,
+        runningRequests: [{
+          ajaxIndex: 'req1'
+        }],
+        ajaxIndex: 'req1'
+      });
+      chartLinearTimeView.propertyDidChange('isRequestRunning');
+      expect(chartLinearTimeView.get('isRequestRunning')).to.be.true;
+    });
+
+    it("isPopup false, no running request", function() {
+      chartLinearTimeView.setProperties({
+        isPopup: false,
+        runningRequests: [],
+        ajaxIndex: 'req1'
+      });
+      chartLinearTimeView.propertyDidChange('isRequestRunning');
+      expect(chartLinearTimeView.get('isRequestRunning')).to.be.false;
+    });
+
+    it("isPopup true, no running request", function() {
+      chartLinearTimeView.setProperties({
+        isPopup: true,
+        runningPopupRequests: [],
+        ajaxIndex: 'req1'
+      });
+      chartLinearTimeView.propertyDidChange('isRequestRunning');
+      expect(chartLinearTimeView.get('isRequestRunning')).to.be.false;
+    });
+
+  });
 
 
   describe('#transformData', function () {
   describe('#transformData', function () {