Browse Source

HUE-9207 [catalog] Support window.dataCatalog.disableCache() for optimizer calls

Johan Ahlen 5 years ago
parent
commit
92967a2d14

+ 5 - 1
desktop/core/src/desktop/js/catalog/dataCatalog.js

@@ -121,7 +121,7 @@ const mergeMultiTableEntry = function(multiTableCatalogEntry, storeEntry) {
   mergeAttribute('topJoins', CACHEABLE_TTL.optimizer, 'topJoinsPromise');
   mergeAttribute('topJoins', CACHEABLE_TTL.optimizer, 'topJoinsPromise');
 };
 };
 
 
-class DataCatalog {
+export class DataCatalog {
   /**
   /**
    * @param {string} sourceType
    * @param {string} sourceType
    * @param {Connector} connector
    * @param {Connector} connector
@@ -157,6 +157,10 @@ class DataCatalog {
     cacheEnabled = true;
     cacheEnabled = true;
   }
   }
 
 
+  static cacheEnabled() {
+    return cacheEnabled;
+  }
+
   /**
   /**
    * Returns true if the catalog can have Optimizer metadata
    * Returns true if the catalog can have Optimizer metadata
    *
    *

+ 30 - 6
desktop/core/src/desktop/js/catalog/dataCatalogEntry.js

@@ -23,6 +23,7 @@ import catalogUtils from 'catalog/catalogUtils';
 import huePubSub from 'utils/huePubSub';
 import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
 import I18n from 'utils/i18n';
 import { getOptimizer } from './optimizer/optimizer';
 import { getOptimizer } from './optimizer/optimizer';
+import { DataCatalog } from './dataCatalog';
 
 
 /**
 /**
  * Helper function to reload the source meta for the given entry
  * Helper function to reload the source meta for the given entry
@@ -404,12 +405,18 @@ class DataCatalogEntry {
    */
    */
   getChildren(options) {
   getChildren(options) {
     const self = this;
     const self = this;
-    if (self.childrenPromise && (!options || !options.refreshCache)) {
+    if (self.childrenPromise && DataCatalog.cacheEnabled() && (!options || !options.refreshCache)) {
       return catalogUtils.applyCancellable(self.childrenPromise, options);
       return catalogUtils.applyCancellable(self.childrenPromise, options);
     }
     }
     const deferred = $.Deferred();
     const deferred = $.Deferred();
 
 
-    if (options && options.cachedOnly && !self.sourceMeta && !self.sourceMetaPromise) {
+    if (
+      DataCatalog.cacheEnabled() &&
+      options &&
+      options.cachedOnly &&
+      !self.sourceMeta &&
+      !self.sourceMetaPromise
+    ) {
       return deferred.reject(false).promise();
       return deferred.reject(false).promise();
     }
     }
 
 
@@ -556,7 +563,11 @@ class DataCatalogEntry {
         .promise();
         .promise();
     }
     }
 
 
-    if (self.navigatorMetaForChildrenPromise && (!options || !options.refreshCache)) {
+    if (
+      self.navigatorMetaForChildrenPromise &&
+      DataCatalog.cacheEnabled() &&
+      (!options || !options.refreshCache)
+    ) {
       return catalogUtils.applyCancellable(self.navigatorMetaForChildrenPromise, options);
       return catalogUtils.applyCancellable(self.navigatorMetaForChildrenPromise, options);
     }
     }
 
 
@@ -571,7 +582,11 @@ class DataCatalogEntry {
           const someHaveNavMeta = children.some(childEntry => {
           const someHaveNavMeta = children.some(childEntry => {
             return childEntry.navigatorMeta;
             return childEntry.navigatorMeta;
           });
           });
-          if (someHaveNavMeta && (!options || !options.refreshCache)) {
+          if (
+            someHaveNavMeta &&
+            DataCatalog.cacheEnabled() &&
+            (!options || !options.refreshCache)
+          ) {
             deferred.resolve(children);
             deferred.resolve(children);
             return;
             return;
           }
           }
@@ -739,12 +754,21 @@ class DataCatalogEntry {
         .reject()
         .reject()
         .promise();
         .promise();
     }
     }
-    if (self.optimizerPopularityForChildrenPromise && (!options || !options.refreshCache)) {
+    if (
+      self.optimizerPopularityForChildrenPromise &&
+      DataCatalog.cacheEnabled() &&
+      (!options || !options.refreshCache)
+    ) {
       return catalogUtils.applyCancellable(self.optimizerPopularityForChildrenPromise, options);
       return catalogUtils.applyCancellable(self.optimizerPopularityForChildrenPromise, options);
     }
     }
     const deferred = $.Deferred();
     const deferred = $.Deferred();
     const cancellablePromises = [];
     const cancellablePromises = [];
-    if (self.definition && self.definition.optimizerLoaded && (!options || !options.refreshCache)) {
+    if (
+      self.definition &&
+      self.definition.optimizerLoaded &&
+      DataCatalog.cacheEnabled() &&
+      (!options || !options.refreshCache)
+    ) {
       cancellablePromises.push(
       cancellablePromises.push(
         self
         self
           .getChildren(options)
           .getChildren(options)

+ 11 - 2
desktop/core/src/desktop/js/catalog/generalDataCatalog.js

@@ -18,6 +18,7 @@ import $ from 'jquery';
 import localforage from 'localforage';
 import localforage from 'localforage';
 
 
 import apiHelper from 'api/apiHelper';
 import apiHelper from 'api/apiHelper';
+import { DataCatalog } from './dataCatalog';
 
 
 const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const DATA_CATALOG_VERSION = 5;
 const DATA_CATALOG_VERSION = 5;
@@ -41,7 +42,11 @@ class GeneralDataCatalog {
    */
    */
   getAllNavigatorTags(options) {
   getAllNavigatorTags(options) {
     const self = this;
     const self = this;
-    if (self.allNavigatorTagsPromise && (!options || !options.refreshCache)) {
+    if (
+      self.allNavigatorTagsPromise &&
+      DataCatalog.cacheEnabled() &&
+      (!options || !options.refreshCache)
+    ) {
       return self.allNavigatorTagsPromise;
       return self.allNavigatorTagsPromise;
     }
     }
 
 
@@ -72,7 +77,11 @@ class GeneralDataCatalog {
       }
       }
     };
     };
 
 
-    if (window.CACHEABLE_TTL.default > 0 && (!options || !options.refreshCache)) {
+    if (
+      window.CACHEABLE_TTL.default > 0 &&
+      DataCatalog.cacheEnabled() &&
+      (!options || !options.refreshCache)
+    ) {
       self.store
       self.store
         .getItem('hue.dataCatalog.allNavTags')
         .getItem('hue.dataCatalog.allNavTags')
         .then(storeEntry => {
         .then(storeEntry => {

+ 3 - 2
desktop/core/src/desktop/js/catalog/multiTableEntry.js

@@ -18,6 +18,7 @@ import $ from 'jquery';
 
 
 import catalogUtils from 'catalog/catalogUtils';
 import catalogUtils from 'catalog/catalogUtils';
 import { getOptimizer } from './optimizer/optimizer';
 import { getOptimizer } from './optimizer/optimizer';
+import { DataCatalog } from './dataCatalog';
 
 
 /**
 /**
  * Helper function to reload a Optimizer multi table attribute, like topAggs or topFilters
  * Helper function to reload a Optimizer multi table attribute, like topAggs or topFilters
@@ -68,7 +69,7 @@ const genericOptimizerGet = function(
   dataAttribute,
   dataAttribute,
   apiHelperFunction
   apiHelperFunction
 ) {
 ) {
-  if (options && options.cachedOnly) {
+  if (DataCatalog.cacheEnabled() && options && options.cachedOnly) {
     return (
     return (
       catalogUtils.applyCancellable(multiTableEntry[promiseAttribute], options) ||
       catalogUtils.applyCancellable(multiTableEntry[promiseAttribute], options) ||
       $.Deferred()
       $.Deferred()
@@ -76,7 +77,7 @@ const genericOptimizerGet = function(
         .promise()
         .promise()
     );
     );
   }
   }
-  if (options && options.refreshCache) {
+  if (!DataCatalog.cacheEnabled() || (options && options.refreshCache)) {
     return catalogUtils.applyCancellable(
     return catalogUtils.applyCancellable(
       genericOptimizerReload(
       genericOptimizerReload(
         multiTableEntry,
         multiTableEntry,