浏览代码

HUE-6940 [editor] Cancel risk requests if editing while risk check is running

Johan Ahlen 8 年之前
父节点
当前提交
e944143
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

+ 8 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -998,6 +998,12 @@ var EditorViewModel = (function() {
         self.complexity({});
         huePubSub.publish('editor.active.risks', {});
 
+        var changeSubscription = self.statement.subscribe(function () {
+          changeSubscription.dispose();
+          self.getApiHelper().cancelActiveRequest(lastComplexityRequest);
+          self.complexityCheckRunning(false);
+        });
+
         lastComplexityRequest = $.ajax({
           type: 'POST',
           url: '/notebook/api/optimizer/statement/risk',
@@ -1018,12 +1024,14 @@ var EditorViewModel = (function() {
             lastCheckedComplexityStatement = self.statement();
           },
           always: function(data) {
+            changeSubscription.dispose();
             self.complexityCheckRunning(false);
           },
           error: function(data) {
             self.complexityCheckRunning(false);
           }
         });
+
       };
 
       if (self.type() === 'hive' || self.type() === 'impala') {