瀏覽代碼

[spark] Fix cache issue with assistHelper

If the database part of the API URL is undefined or null any calls will still come back as a a success, a code is instead used which could represent an error. This commit will prevent caching of a response with code 500. I've also added an additional check to make sure there's an active database before fetching the tables in the ace binding.
Johan Ahlen 10 年之前
父節點
當前提交
82a3ddf

+ 10 - 6
desktop/core/src/desktop/static/desktop/js/assistHelper.js

@@ -156,12 +156,16 @@ AssistHelper.prototype.fetchAssistData = function (url, successCallback, errorCa
       type: "GET",
       url: url + "?" + Math.random(),
       success: function (data) {
-        cachedData[url] = {
-          timestamp: (new Date()).getTime(),
-          data: data
-        };
-        $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(), cachedData);
-        successCallback(data);
+        if (data.code === 500){
+          errorCallback(data.error);
+        } else {
+          cachedData[url] = {
+            timestamp: (new Date()).getTime(),
+            data: data
+          };
+          $.totalStorage("hue.assist." + self.getTotalStorageUserPrefix(), cachedData);
+          successCallback(data);
+        }
       },
       error: errorCallback
     });

+ 7 - 5
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -1753,11 +1753,13 @@ ko.bindingHandlers.aceEditor = {
 
     var refreshTables = function() {
       currentAssistTables = {};
-      self.assistHelper.fetchTables(function(data) {
-        $.each(data.tables, function(index, table) {
-          currentAssistTables[table] = true;
-        });
-      })
+      if (typeof self.assistHelper.activeDatabase() != undefined && self.assistHelper.activeDatabase() != null) {
+        self.assistHelper.fetchTables(function(data) {
+          $.each(data.tables, function(index, table) {
+            currentAssistTables[table] = true;
+          });
+        })
+      }
     };
     self.assistHelper.activeDatabase.subscribe(refreshTables);
     refreshTables();