浏览代码

HUE-9207 [frontend] Don't persist local optimizer results in the IndexedDB

Johan Ahlen 5 年之前
父节点
当前提交
a0cbd3e148

+ 20 - 6
desktop/core/src/desktop/js/catalog/dataCatalog.js

@@ -22,7 +22,7 @@ import catalogUtils from 'catalog/catalogUtils';
 import DataCatalogEntry from 'catalog/dataCatalogEntry';
 import DataCatalogEntry from 'catalog/dataCatalogEntry';
 import GeneralDataCatalog from 'catalog/generalDataCatalog';
 import GeneralDataCatalog from 'catalog/generalDataCatalog';
 import MultiTableEntry from 'catalog/multiTableEntry';
 import MultiTableEntry from 'catalog/multiTableEntry';
-import { getOptimizer } from './optimizer/optimizer';
+import { getOptimizer, LOCAL_STRATEGY } from './optimizer/optimizer';
 
 
 const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const DATA_CATALOG_VERSION = 5;
 const DATA_CATALOG_VERSION = 5;
@@ -88,8 +88,10 @@ const mergeEntry = function(dataCatalogEntry, storeEntry) {
   mergeAttribute('partitions', CACHEABLE_TTL.default, 'partitionsPromise');
   mergeAttribute('partitions', CACHEABLE_TTL.default, 'partitionsPromise');
   mergeAttribute('sample', CACHEABLE_TTL.default, 'samplePromise');
   mergeAttribute('sample', CACHEABLE_TTL.default, 'samplePromise');
   mergeAttribute('navigatorMeta', CACHEABLE_TTL.default, 'navigatorMetaPromise');
   mergeAttribute('navigatorMeta', CACHEABLE_TTL.default, 'navigatorMetaPromise');
-  mergeAttribute('optimizerMeta', CACHEABLE_TTL.optimizer, 'optimizerMetaPromise');
-  mergeAttribute('optimizerPopularity', CACHEABLE_TTL.optimizer);
+  if (dataCatalogEntry.getConnector().optimizer !== LOCAL_STRATEGY) {
+    mergeAttribute('optimizerMeta', CACHEABLE_TTL.optimizer, 'optimizerMetaPromise');
+    mergeAttribute('optimizerPopularity', CACHEABLE_TTL.optimizer);
+  }
 };
 };
 
 
 /**
 /**
@@ -99,6 +101,9 @@ const mergeEntry = function(dataCatalogEntry, storeEntry) {
  * @param {Object} storeEntry - The cached version
  * @param {Object} storeEntry - The cached version
  */
  */
 const mergeMultiTableEntry = function(multiTableCatalogEntry, storeEntry) {
 const mergeMultiTableEntry = function(multiTableCatalogEntry, storeEntry) {
+  if (multiTableCatalogEntry.getConnector().optimizer === LOCAL_STRATEGY) {
+    return;
+  }
   const mergeAttribute = function(attributeName, ttl, promiseName) {
   const mergeAttribute = function(attributeName, ttl, promiseName) {
     if (
     if (
       storeEntry.version === DATA_CATALOG_VERSION &&
       storeEntry.version === DATA_CATALOG_VERSION &&
@@ -255,8 +260,12 @@ export class DataCatalog {
         partitions: dataCatalogEntry.partitions,
         partitions: dataCatalogEntry.partitions,
         sample: dataCatalogEntry.sample,
         sample: dataCatalogEntry.sample,
         navigatorMeta: dataCatalogEntry.navigatorMeta,
         navigatorMeta: dataCatalogEntry.navigatorMeta,
-        optimizerMeta: dataCatalogEntry.optimizerMeta,
-        optimizerPopularity: dataCatalogEntry.optimizerPopularity
+        optimizerMeta:
+          this.connector.optimizer !== LOCAL_STRATEGY ? dataCatalogEntry.optimizerMeta : undefined,
+        optimizerPopularity:
+          this.connector.optimizer !== LOCAL_STRATEGY
+            ? dataCatalogEntry.optimizerPopularity
+            : undefined
       })
       })
       .then(deferred.resolve)
       .then(deferred.resolve)
       .catch(deferred.reject);
       .catch(deferred.reject);
@@ -793,7 +802,12 @@ export class DataCatalog {
    */
    */
   persistMultiTableEntry(multiTableEntry) {
   persistMultiTableEntry(multiTableEntry) {
     const self = this;
     const self = this;
-    if (!cacheEnabled || CACHEABLE_TTL.default <= 0 || CACHEABLE_TTL.optimizer <= 0) {
+    if (
+      !cacheEnabled ||
+      CACHEABLE_TTL.default <= 0 ||
+      CACHEABLE_TTL.optimizer <= 0 ||
+      multiTableEntry.getConnector().optimizer === LOCAL_STRATEGY
+    ) {
       return $.Deferred()
       return $.Deferred()
         .resolve()
         .resolve()
         .promise();
         .promise();

+ 5 - 2
desktop/core/src/desktop/js/catalog/optimizer/optimizer.js

@@ -20,12 +20,15 @@ import LocalStrategy from './localStrategy';
 
 
 const optimizerInstances = {};
 const optimizerInstances = {};
 
 
+export const LOCAL_STRATEGY = 'local';
+export const API_STRATEGY = 'api';
+
 const createOptimizer = connector => {
 const createOptimizer = connector => {
   // TODO: Remove window.OPTIMIZER_MODE and hardcoded { optimizer: 'api' } when 'connector.optimizer_mode' works.
   // TODO: Remove window.OPTIMIZER_MODE and hardcoded { optimizer: 'api' } when 'connector.optimizer_mode' works.
-  if (window.OPTIMIZER_MODE === 'local') {
+  if (window.OPTIMIZER_MODE === LOCAL_STRATEGY) {
     return new LocalStrategy(connector);
     return new LocalStrategy(connector);
   }
   }
-  if (window.OPTIMIZER_MODE === 'api') {
+  if (window.OPTIMIZER_MODE === API_STRATEGY) {
     return new ApiStrategy(connector);
     return new ApiStrategy(connector);
   }
   }
   return new BaseStrategy(connector);
   return new BaseStrategy(connector);