Browse Source

[assist] Make the assistHelper singleton to fix caching issues

There's some state kept in the assist helper to simplify the autocompleter, this change guarantees that also this gets cleared when the assist is refreshed.

This also removes the index of assist helpers by type from the notebook (the type doesn't matter anymore to the assist helper), by doing so it also fixes another caching issue with the notebook snippets that use the helper.
Johan Ahlen 10 years ago
parent
commit
6d069f5

+ 1 - 1
apps/beeswax/src/beeswax/templates/create_database.mako

@@ -252,7 +252,7 @@ ${ assist.assistPanel() }
       self.assistAvailable = ko.observable(true);
       self.assistAvailable = ko.observable(true);
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-      self.assistHelper = new AssistHelper(options);
+      self.assistHelper = AssistHelper.getInstance(options);
 
 
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;

+ 1 - 1
apps/beeswax/src/beeswax/templates/create_table_manually.mako

@@ -550,7 +550,7 @@ ${ assist.assistPanel() }
       self.assistAvailable = ko.observable(true);
       self.assistAvailable = ko.observable(true);
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-      self.assistHelper = new AssistHelper(options);
+      self.assistHelper = AssistHelper.getInstance(options);
 
 
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;

+ 1 - 1
apps/beeswax/src/beeswax/templates/import_wizard_choose_delimiter.mako

@@ -205,7 +205,7 @@ ${ assist.assistPanel() }
       self.assistAvailable = ko.observable(true);
       self.assistAvailable = ko.observable(true);
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-      self.assistHelper = new AssistHelper(options);
+      self.assistHelper = AssistHelper.getInstance(options);
 
 
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;

+ 1 - 1
apps/beeswax/src/beeswax/templates/import_wizard_choose_file.mako

@@ -228,7 +228,7 @@ ${ assist.assistPanel() }
       self.assistAvailable = ko.observable(true);
       self.assistAvailable = ko.observable(true);
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-      self.assistHelper = new AssistHelper(options);
+      self.assistHelper = AssistHelper.getInstance(options);
 
 
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;

+ 1 - 1
apps/beeswax/src/beeswax/templates/import_wizard_define_columns.mako

@@ -239,7 +239,7 @@ ${ assist.assistPanel() }
       self.assistAvailable = ko.observable(true);
       self.assistAvailable = ko.observable(true);
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-      self.assistHelper = new AssistHelper(options);
+      self.assistHelper = AssistHelper.getInstance(options);
 
 
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
       huePubSub.subscribe("assist.table.selected", function (tableDef) {
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;
         location.href = '/metastore/table/' + tableDef.database + '/' + tableDef.name;

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

@@ -430,7 +430,7 @@
     self.assistAvailable = ko.observable(true);
     self.assistAvailable = ko.observable(true);
     self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
     self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-    self.assistHelper = new AssistHelper(options);
+    self.assistHelper = AssistHelper.getInstance(options);
 
 
     self.reloading = ko.observable(false);
     self.reloading = ko.observable(false);
     self.loading = ko.observable(false);
     self.loading = ko.observable(false);

+ 1 - 1
apps/metastore/src/metastore/templates/describe_partitions.mako

@@ -191,7 +191,7 @@ ${ assist.assistPanel() }
       self.assistAvailable = ko.observable(true);
       self.assistAvailable = ko.observable(true);
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
       self.isLeftPanelVisible = ko.observable(self.assistAvailable() && $.totalStorage('spark_left_panel_visible') != null && $.totalStorage('spark_left_panel_visible'));
 
 
-      self.assistHelper = new AssistHelper(options);
+      self.assistHelper = AssistHelper.getInstance(options);
 
 
       self.isLoading = ko.observable(false);
       self.isLoading = ko.observable(false);
 
 

+ 20 - 1
desktop/core/src/desktop/static/desktop/js/assist/assistHelper.js

@@ -462,5 +462,24 @@
     }
     }
   };
   };
 
 
-  return AssistHelper;
+  var instance = null;
+
+  return {
+
+    /**
+     * @param {Object} options
+     * @param {Object} options.i18n
+     * @param {string} options.i18n.errorLoadingDatabases
+     * @param {string} options.i18n.errorLoadingTablePreview
+     * @param {string} options.user
+     *
+     * @returns {AssistHelper}
+     */
+    getInstance: function (options) {
+      if (instance === null) {
+        instance = new AssistHelper(options.i18n, options.user);
+      }
+      return instance;
+    }
+  };
 }));
 }));

+ 4 - 1
desktop/core/src/desktop/static/desktop/spec/hdfsAutocompleterSpec.js

@@ -26,7 +26,10 @@ define([
       responseForUrls: {}
       responseForUrls: {}
     };
     };
 
 
-    var assistHelper = new AssistHelper({}, "testUser");
+    var assistHelper = AssistHelper.getInstance({
+      i18n: {},
+      user: 'testUser'
+    });
 
 
     var snippet = {
     var snippet = {
       type: ko.observable(),
       type: ko.observable(),

+ 4 - 1
desktop/core/src/desktop/static/desktop/spec/sqlAutocompleterSpec.js

@@ -26,7 +26,10 @@ define([
       responseForUrls: {}
       responseForUrls: {}
     };
     };
 
 
-    var assistHelper = new AssistHelper({}, "testUser");
+    var assistHelper = AssistHelper.getInstance({
+      i18n: {},
+      user: 'testUser'
+    });
 
 
     var snippet = {
     var snippet = {
       type: ko.observable(),
       type: ko.observable(),

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

@@ -688,7 +688,10 @@ from desktop.views import _ko
             'notebook' : "${ _('Notebook') }"
             'notebook' : "${ _('Notebook') }"
           }
           }
         };
         };
-        self.assistHelper = new AssistHelper(i18n, params.user);
+        self.assistHelper = AssistHelper.getInstance({
+          i18n: i18n,
+          user: params.user
+        });
 
 
         self.onlySql = params.onlySql;
         self.onlySql = params.onlySql;
         self.loading = ko.observable(false);
         self.loading = ko.observable(false);

+ 1 - 12
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -170,7 +170,7 @@
     };
     };
 
 
     self.getAssistHelper = function() {
     self.getAssistHelper = function() {
-      return notebook.getAssistHelper(self.type());
+      return AssistHelper.getInstance(vm);
     };
     };
 
 
     self.database = ko.observable(typeof snippet.database != "undefined" && snippet.database != null ? snippet.database : null);
     self.database = ko.observable(typeof snippet.database != "undefined" && snippet.database != null ? snippet.database : null);
@@ -731,7 +731,6 @@
       }
       }
     });
     });
 
 
-    self.assistHelpers = {};
     self.history = ko.observableArray([]);
     self.history = ko.observableArray([]);
     self.showHistory = ko.observable(typeof notebook.showHistory != "undefined" && notebook.showHistory != null ? notebook.showHistory : false);
     self.showHistory = ko.observable(typeof notebook.showHistory != "undefined" && notebook.showHistory != null ? notebook.showHistory : false);
     self.showHistory.subscribe(function (val) {
     self.showHistory.subscribe(function (val) {
@@ -740,16 +739,6 @@
       }
       }
     });
     });
 
 
-    self.getAssistHelper = function (snippetType) {
-      if (! self.assistHelpers[snippetType]) {
-        self.assistHelpers[snippetType] = new AssistHelper({
-          user: vm.user,
-          i18n: vm.i18n
-        }, vm.i18n);
-      }
-      return self.assistHelpers[snippetType]
-    };
-
     self.getSession = function (session_type) {
     self.getSession = function (session_type) {
       var _s = null;
       var _s = null;
       $.each(self.sessions(), function (index, s) {
       $.each(self.sessions(), function (index, s) {