Переглянути джерело

HUE-7820 [metastore] Only refresh the open entity in the table browser instead of refreshing everything

Johan Ahlen 7 роки тому
батько
коміт
45c11ad7b2

+ 50 - 31
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -76,47 +76,66 @@ var MetastoreViewModel = (function () {
 
     self.loadDatabases();
 
-    self.refresh = function () {
-      if (self.sourceType() === 'impala') {
-        huePubSub.publish('assist.invalidate.on.refresh');
-      }
-      huePubSub.publish('assist.db.refresh', { sourceTypes: [ self.sourceType() ] });
-    };
+    huePubSub.subscribe('data.catalog.entry.refreshed', function (refreshedEntry) {
 
-    huePubSub.subscribe('assist.db.refresh', function (options) {
-      if (typeof options.sourceTypes !== 'undefined' && options.sourceTypes.indexOf('hive') === -1 && options.sourceTypes.indexOf('impala') === -1 ) {
+      if (refreshedEntry.getSourceType() !== self.sourceType()) {
         return;
       }
-      self.reloading(true);
-      huePubSub.publish('assist.clear.db.cache', {
-        sourceType: 'hive',
-        clearAll: true
-      });
-      huePubSub.publish('assist.clear.db.cache', {
-        sourceType: 'impala',
-        clearAll: true
-      });
-      var currentDatabase = null;
-      var currentTable = null;
+
+      var prevDbName = null;
+      var prevTableName = null;
       if (self.database()) {
-        currentDatabase = self.database().catalogEntry.name;
+        prevDbName = self.database().catalogEntry.name;
         if (self.database().table()) {
-          currentTable = self.database().table().catalogEntry.name;
-          self.database().table(null);
+          prevTableName = self.database().table().catalogEntry.name;
         }
-        self.database(null);
       }
-      self.loadDatabases.done(function () {
-        if (currentDatabase) {
-          self.setDatabaseByName(currentDatabase, function () {
-            if (self.database() && currentTable) {
-              self.database().setTableByName(currentTable);
+
+      var setPrevious = function () {
+        if (prevDbName) {
+          self.setDatabaseByName(prevDbName, function () {
+            if (self.database() && prevTableName) {
+              self.database().setTableByName(prevTableName);
             }
           });
         }
-      }).always(function () {
-        self.reloading(false);
-      });
+      };
+
+      var completeRefresh = function () {
+        self.reloading(true);
+        if (self.database() && self.database().table()) {
+          self.database().table(null);
+        }
+        if (self.database()) {
+          self.database(null);
+        }
+        self.loadDatabases().done(setPrevious).always(function () {
+          self.reloading(false);
+        });
+      };
+
+      if (refreshedEntry.isSource()) {
+        completeRefresh();
+      } else if (refreshedEntry.isDatabase()) {
+        self.databases().some(function (database) {
+          if (database.catalogEntry === refreshedEntry) {
+            database.load(setPrevious, self.optimizerEnabled(), self.navigatorEnabled());
+            return true;
+          }
+        })
+      } else if (refreshedEntry.isTable()) {
+        self.databases().some(function (database) {
+          if (database.catalogEntry.name === refreshedEntry.path[0]) {
+            database.tables().some(function (table) {
+              if (table.catalogEntry.name === refreshedEntry.name) {
+                table.load();
+                return true;
+              }
+            });
+            return true;
+          }
+        })
+      }
     });
 
     huePubSub.subscribe("assist.table.selected", function (tableDef) {

+ 11 - 5
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -133,7 +133,12 @@ var MetastoreDatabase = (function () {
 
   MetastoreDatabase.prototype.setTableByName = function (tableName) {
     var self = this;
-    var foundTables = $.grep(self.tables(), function (metastoreTable) {
+
+    if (self.table() && self.table().catalogEntry.name === tableName) {
+      return;
+    }
+
+    var foundTables = self.tables().filter(function (metastoreTable) {
       return metastoreTable.catalogEntry.name === tableName;
     });
 
@@ -407,7 +412,7 @@ var MetastoreTable = (function () {
       self.apiHelper.refreshTableStats({
         tableName: self.catalogEntry.name,
         databaseName: self.database.catalogEntry.name,
-        sourceType: self.catalogEntry.dataCatalog.sourceType,
+        sourceType: self.catalogEntry.getSourceType(),
         successCallback: function () {
           self.fetchDetails();
         },
@@ -443,7 +448,7 @@ var MetastoreTable = (function () {
 
       // TODO: Move to DataCatalogEntry
       self.apiHelper.fetchTableDetails({
-        sourceType: self.catalogEntry.dataCatalog.sourceType,
+        sourceType: self.catalogEntry.getSourceType(),
         databaseName: self.database.catalogEntry.name,
         tableName: self.catalogEntry.name,
         successCallback: function (data) {
@@ -573,6 +578,7 @@ var MetastoreTable = (function () {
     }
     self.loading(true);
     self.fetchFields();
+    self.refreshTableStats();
     self.fetchDetails();
     huePubSub.publish('metastore.loaded.table');
   };
@@ -590,7 +596,7 @@ var MetastoreTable = (function () {
         identifierChain: [{ name: entry.catalogEntry.name }]
       },
       orientation: orientation || 'right',
-      sourceType: entry.catalogEntry.dataCatalog.sourceType,
+      sourceType: entry.catalogEntry.getSourceType(),
       defaultDatabase: entry.database.catalogEntry.name,
       source: {
         element: event.target,
@@ -656,7 +662,7 @@ var MetastoreColumn = (function () {
         identifierChain: [{ name: entry.table.catalogEntry.name }, { name: entry.catalogEntry.name }]
       },
       orientation: 'right',
-      sourceType: entry.catalogEntry.dataCatalog.sourceType,
+      sourceType: entry.catalogEntry.getSourceType(),
       defaultDatabase: entry.table.database.catalogEntry.name,
       source: {
         element: event.target,

+ 5 - 6
apps/metastore/src/metastore/templates/metastore.mako

@@ -282,9 +282,8 @@ ${ components.menubar(is_embeddable) }
 </script>
 
 <script type="text/html" id="metastore-table-properties">
-  <i data-bind="visible: loadingDetails" class="fa fa-spinner fa-spin fa-2x muted" style="display: none;"></i>
   <!-- ko with: tableDetails -->
-  <h4>${ _('Properties') }</h4>
+  <h4>${ _('Properties') } <i data-bind="visible: $parent.loadingDetails()" class="fa fa-spinner fa-spin" style="display: none;"></i></h4>
   <div class="row-fluid">
     <div title="${ _('Type') }">
       <!-- ko if: is_view -->
@@ -609,7 +608,7 @@ ${ components.menubar(is_embeddable) }
 
 <script type="text/html" id="metastore-databases-actions">
   <div class="inline-block pull-right">
-    <a class="inactive-action" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('assist.db.refresh', { sourceTypes: [sourceType()] }); }">
+    <a class="inactive-action" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, publish: { 'data.catalog.refresh.entry': { invalidate: true, sourceType: sourceType(), path: [] }}">
       <i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }" title="${_('Refresh')}"></i>
     </a>
     % if has_write_access:
@@ -626,7 +625,7 @@ ${ components.menubar(is_embeddable) }
 
 <script type="text/html" id="metastore-tables-actions">
   <div class="inline-block pull-right">
-    <a class="inactive-action" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: refresh" title="${_('Refresh')}"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
+    <a class="inactive-action" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, publish: { 'data.catalog.refresh.entry': { invalidate: true, catalogEntry: database().catalogEntry } }" title="${_('Refresh')}"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
     % if has_write_access:
       % if is_embeddable:
         <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('open.link', '${ url('indexer:importer_prefill', source_type='all', target_type='table') }' + database().catalogEntry.name ); }" title="${_('Create a new table')}" href="javascript:void(0)"><i class="fa fa-plus"></i></a>
@@ -654,7 +653,7 @@ ${ components.menubar(is_embeddable) }
     % else:
       <a class="inactive-action" data-bind="tooltip: { placement: 'bottom', delay: 750 }, attr: { 'href': '/metastore/table/'+ catalogEntry.path.join('/') + '/read' }" title="${_('Browse Data')}"><i class="fa fa-play fa-fw"></i></a>
     % endif
-    <a class="inactive-action" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('assist.db.refresh', { sourceTypes: [$root.sourceType()] }); }" title="${_('Refresh')}" href="javascript:void(0)"><i class="pointer fa fa-refresh fa-fw" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
+    <a class="inactive-action" data-bind="tooltip: { placement: 'bottom', delay: 750 }, publish: { 'data.catalog.refresh.entry': { invalidate: true, catalogEntry: catalogEntry } }" title="${_('Refresh')}" href="javascript:void(0)"><i class="pointer fa fa-refresh fa-fw" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
     % if has_write_access:
       <a class="inactive-action" href="#" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: showImportData, visible: tableDetails() && ! tableDetails().is_view" title="${_('Import Data')}"><i class="fa fa-upload fa-fw"></i></a>
     % endif
@@ -1414,7 +1413,7 @@ ${ components.menubar(is_embeddable) }
       ko.applyBindings(viewModel, $('#metastoreComponents')[0]);
 
       if (location.getParameter('refresh') === 'true') {
-        huePubSub.publish('assist.db.refresh', { sourceTypes: [viewModel.sourceType()] });
+        huePubSub.publish('data.catalog.refresh.entry', { sourceType: viewModel.sourceType(), path: [] });
         hueUtils.replaceURL('?');
       }