Browse Source

AMBARI-16260. Hive View: Prevent multiple /database calls when the first call takes time or fails. (dipayanb)

Dipayan Bhowmick 9 years ago
parent
commit
e04bca9ba0

+ 19 - 6
contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js

@@ -32,6 +32,8 @@ export default Ember.Controller.extend({
 
   tableSearchResults: Ember.Object.create(),
 
+  isDatabaseRefreshInProgress: false,
+
   tableControls: [
     {
       icon: 'fa-list',
@@ -157,6 +159,8 @@ export default Ember.Controller.extend({
     var self = this;
     var selectedDatabase = this.get('selectedDatabase.name') || 'default';
 
+    this.set('isDatabaseRefreshInProgress', true);
+
     this.set('isLoading', true);
 
     this.get('databaseService').getDatabases().then(function (databases) {
@@ -168,12 +172,13 @@ export default Ember.Controller.extend({
       if(error.status == 401) {
          self.send('passwordLDAPDB');
       }
-
-
+    }).finally(function() {
+      self.set('isDatabaseRefreshInProgress', false);
     });
   }.on('init'),
 
   syncDatabases: function() {
+    this.set('isDatabaseRefreshInProgress', true);
     var oldDatabaseNames = this.store.all('database').mapBy('name');
     var self = this;
     return this.get('databaseService').getDatabasesFromServer().then(function(data) {
@@ -194,6 +199,8 @@ export default Ember.Controller.extend({
           });
         }
       });
+    }).finally(function() {
+      self.set('isDatabaseRefreshInProgress', false);
     });
   },
 
@@ -201,8 +208,10 @@ export default Ember.Controller.extend({
     // This was required so that the unit test would not stall
     if(ENV.environment !== "test") {
       Ember.run.later(this, function() {
-        this.syncDatabases();
-        this.initiateDatabaseSync();
+        if (this.get('isDatabaseRefreshInProgress') === false) {
+          this.syncDatabases();
+          this.initiateDatabaseSync();
+        }
       }, 15000);
     }
   }.on('init'),
@@ -222,8 +231,12 @@ export default Ember.Controller.extend({
 
   actions: {
     refreshDatabaseExplorer: function () {
-      this.getDatabases();
-      this.resetSearch();
+      if (this.get('isDatabaseRefreshInProgress') === false) {
+        this.getDatabases();
+        this.resetSearch();
+      } else {
+        console.log("Databases refresh is in progress. Skipping this request.");
+      }
     },
 
     passwordLDAPDB: function(){