Эх сурвалжийг харах

HUE-5445 [assist] Enable shift-click on refresh to clear all caches

Mainly useful when developing
Johan Ahlen 9 жил өмнө
parent
commit
5634fb4

+ 2 - 2
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -819,8 +819,8 @@ var MetastoreViewModel = (function () {
       }
     };
 
-    huePubSub.subscribe('assist.db.refresh', function (type) {
-      if (type !== 'hive') {
+    huePubSub.subscribe('assist.db.refresh', function (options) {
+      if (options.sourceType !== 'hive') {
         return;
       }
       self.reloading(true);

+ 4 - 4
apps/metastore/src/metastore/templates/metastore.mako

@@ -540,7 +540,7 @@ ${ components.menubar() }
 
 <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', 'hive'); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }" title="${_('Refresh')}"></i></a>
+    <a class="inactive-action" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('assist.db.refresh', { sourceType: 'hive' }); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }" title="${_('Refresh')}"></i></a>
     % if has_write_access:
     <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }" href="${ url('beeswax:create_database') }" title="${_('Create a new database')}"><i class="fa fa-plus"></i></a>
     % endif
@@ -549,7 +549,7 @@ ${ components.menubar() }
 
 <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: function () { huePubSub.publish('assist.db.refresh', 'hive'); }" 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 }, click: function () { huePubSub.publish('assist.db.refresh', { sourceType: 'hive' }); }" title="${_('Refresh')}"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
     % if has_write_access:
     <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }, attr: { 'href': '/beeswax/create/import_wizard/' + database().name }" title="${_('Create a new table from a file')}"><span class="fa-stack fa-fw" style="width: 1.28571429em"><i class="fa fa-file-o fa-stack-1x"></i><i class="fa fa-plus-circle fa-stack-1x" style="font-size: 14px; margin-left: 5px; margin-top: 6px;"></i></span></a>
     <a class="inactive-action margin-left-10" data-bind="tooltip: { placement: 'bottom', delay: 750 }, attr: { 'href': '/beeswax/create/create_table/' + database().name }" title="${_('Create a new table manually')}"><i class="fa fa-plus"></i></a>
@@ -566,7 +566,7 @@ ${ components.menubar() }
     % else:
       <a class="inactive-action" data-bind="tooltip: { placement: 'bottom', delay: 750 }, attr: { 'href': '/metastore/table/'+ database.name + '/' + name + '/read' }" title="${_('Browse Data')}"><i class="fa fa-list"></i></a>
     % endif
-    <a class="inactive-action margin-left-10" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('assist.db.refresh', 'hive'); }" title="${_('Refresh')}"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
+    <a class="inactive-action margin-left-10" href="javascript:void(0)" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function () { huePubSub.publish('assist.db.refresh', { sourceType: 'hive' }); }" title="${_('Refresh')}"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : $root.reloading }"></i></a>
     <!-- ko if: $root.optimizerEnabled() && $root.database().table().optimizerStats() -->
       <a class="inactive-action margin-left-10" title="${_('View in Optimizer')}" data-bind="tooltip: { placement: 'bottom', delay: 750 }, attr: { 'href': $root.optimizerUrl() + '#/table/' + $root.database().table().optimizerStats().eid }" target="_blank"><i class="fa fa-skyatlas"></i></a>
     <!-- /ko -->
@@ -1263,7 +1263,7 @@ ${ components.menubar() }
       ko.applyBindings(viewModel, $('#metastoreComponents')[0]);
 
       if (location.getParameter('refresh') === 'true') {
-        huePubSub.publish('assist.db.refresh', 'hive');
+        huePubSub.publish('assist.db.refresh', { sourceType: 'hive' });
         hueUtils.replaceURL('?');
       }
 

+ 9 - 7
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -726,14 +726,16 @@ var ApiHelper = (function () {
    * @param {string} [options.databaseName]
    * @param {boolean} [options.invalidateImpala]
    * @param {string} [options.tableName]
+   * @param {string} [options.cacheType] - Possible values 'default', 'optimizer. Default value 'default'
    * @param {string[]} [options.fields]
    * @param {boolean} [options.clearAll]
    */
   ApiHelper.prototype.clearDbCache = function (options) {
     var self = this;
     self.invalidateImpala = options.invalidateImpala || 'cache';
+    var cacheIdentifier = "hue.assist." + (options.cacheType || 'default') + '.' + self.getTotalStorageUserPrefix(options.sourceType);
     if (options.clearAll) {
-      $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(options.sourceType), {});
+      $.totalStorage(cacheIdentifier, {});
     } else {
       var url = AUTOCOMPLETE_API_PREFIX;
       if (options.databaseName) {
@@ -745,9 +747,9 @@ var ApiHelper = (function () {
       if (options.fields) {
         url += options.fields.length > 0 ? "/" + options.fields.join("/") : "";
       }
-      var cachedData = $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(options.sourceType)) || {};
+      var cachedData = $.totalStorage(cacheIdentifier) || {};
       delete cachedData[url];
-      $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(options.sourceType), cachedData);
+      $.totalStorage(cacheIdentifier, cachedData);
     }
   };
 
@@ -1615,7 +1617,7 @@ var ApiHelper = (function () {
    * @param {Function} options.cacheCondition - Determines whether it should be cached or not
    * @param {Function} options.successCallback
    * @param {Function} options.errorCallback
-   * @param {string} [options.cacheType] - Possible values 'default'|'optimizer'. Default value 'default'
+   * @param {string} [options.cacheType] - Possible values 'default', 'optimizer'. Default value 'default'
    * @param {Number} [options.timeout]
    * @param {Object} [options.editor] - Ace editor
    */
@@ -1705,9 +1707,9 @@ var ApiHelper = (function () {
    * @param {Object} [options.editor] - Ace editor
    */
   var fetchCached = function (options) {
-    console.log(options.url + ' ' + options.cacheType);
     var self = this;
-    var cachedData = $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(options.sourceType)) || {};
+    var cacheIdentifier = "hue.assist." + (options.cacheType || 'default') + '.' + self.getTotalStorageUserPrefix(options.sourceType);
+    var cachedData = $.totalStorage(cacheIdentifier) || {};
     var cachedId = options.hash ? options.url + options.hash : options.url;
 
     if (typeof cachedData[cachedId] == "undefined" || self.hasExpired(cachedData[cachedId].timestamp, options.cacheType || 'default')) {
@@ -1719,7 +1721,7 @@ var ApiHelper = (function () {
           timestamp: (new Date()).getTime(),
           data: data
         };
-        $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(options.sourceType), cachedData);
+        $.totalStorage(cacheIdentifier, cachedData);
       });
     } else {
       options.successCallback(cachedData[cachedId].data);

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -239,9 +239,9 @@ var AssistDbEntry = (function () {
     self.editingSearch(self.isSearchVisible());
   };
 
-  AssistDbEntry.prototype.triggerRefresh = function () {
+  AssistDbEntry.prototype.triggerRefresh = function (data, event) {
     var self = this;
-    self.assistDbSource.triggerRefresh();
+    self.assistDbSource.triggerRefresh(data, event);
   };
 
   AssistDbEntry.prototype.highlightInside = function (path) {

+ 13 - 6
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -264,20 +264,27 @@ var AssistDbSource = (function () {
       $container.find(".assist-actions, .assist-db-header-actions").css('right', -$container.scrollLeft() + 'px');
     };
 
-    self.reload = function() {
+    self.reload = function(allCacheTypes) {
       self.reloading(true);
       huePubSub.publish('assist.clear.db.cache', {
         sourceType: self.sourceType,
         clearAll: true,
         invalidateImpala: self.invalidateOnRefresh()
       });
+      if (allCacheTypes) {
+        huePubSub.publish('assist.clear.db.cache', {
+          sourceType: self.sourceType,
+          cacheType: 'optimizer',
+          clearAll: true
+        });
+      }
       self.invalidateOnRefresh('cache');
       self.initDatabases();
     };
 
-    huePubSub.subscribe('assist.db.refresh', function (type) {
-      if (self.sourceType === type) {
-        self.reload();
+    huePubSub.subscribe('assist.db.refresh', function (options) {
+      if (self.sourceType === options.sourceType) {
+        self.reload(options.allCacheTypes);
       }
     });
   }
@@ -326,9 +333,9 @@ var AssistDbSource = (function () {
     self.editingSearch(self.isSearchVisible());
   };
 
-  AssistDbSource.prototype.triggerRefresh = function () {
+  AssistDbSource.prototype.triggerRefresh = function (data, event) {
     var self = this;
-    huePubSub.publish('assist.db.refresh', self.sourceType);
+    huePubSub.publish('assist.db.refresh', { sourceType: self.sourceType, allCacheTypes: event.shiftKey });
   };
 
   return AssistDbSource;

+ 1 - 1
desktop/core/src/desktop/templates/assist.mako

@@ -1022,7 +1022,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
       ${ _('Invalidate all metadata and rebuild index') }
     </label>
     <div style="display: inline-block; margin-left: 20px; font-style: italic; color: #999;">${ _('WARNING: This can be both resource and time-intensive.') }</div>
-    <div style="width: 100%; display: inline-block; margin-top: 5px;"><button class="pull-right btn btn-primary" data-bind="css: { 'btn-primary': invalidateOnRefresh() !== 'invalidateAndFlush', 'btn-danger': invalidateOnRefresh() === 'invalidateAndFlush' }, click: function () { huePubSub.publish('close.popover'); triggerRefresh(); }, clickBubble: false">${ _('Refresh') }</button></div>
+    <div style="width: 100%; display: inline-block; margin-top: 5px;"><button class="pull-right btn btn-primary" data-bind="css: { 'btn-primary': invalidateOnRefresh() !== 'invalidateAndFlush', 'btn-danger': invalidateOnRefresh() === 'invalidateAndFlush' }, click: function (data, event) { huePubSub.publish('close.popover'); triggerRefresh(data, event); }, clickBubble: false">${ _('Refresh') }</button></div>
   </script>
 
   <script type="text/html" id="assist-db-header-actions">

+ 3 - 3
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -315,8 +315,8 @@ var EditorViewModel = (function() {
       }
     };
 
-    huePubSub.subscribe('assist.db.refresh', function (type) {
-      if (self.type() == type) {
+    huePubSub.subscribe('assist.db.refresh', function (options) {
+      if (self.type() == options.sourceType) {
         updateDatabases();
       }
     });
@@ -581,7 +581,7 @@ var EditorViewModel = (function() {
     self.delayedDDLNotification = ko.pureComputed(self.ddlNotification).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 5000 } });
     window.setTimeout(function () {
       self.delayedDDLNotification.subscribe(function (val) {
-        huePubSub.publish('assist.db.refresh', self.type());
+        huePubSub.publish('assist.db.refresh', { sourceType: self.type() });
       });
     }, 0);