소스 검색

HUE-3862 [editor] Fetch status timers are not cleared when switching queries

Romain Rigaux 9 년 전
부모
커밋
03074fa
2개의 변경된 파일19개의 추가작업 그리고 7개의 파일을 삭제
  1. 3 2
      desktop/libs/notebook/src/notebook/decorators.py
  2. 16 5
      desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

+ 3 - 2
desktop/libs/notebook/src/notebook/decorators.py

@@ -86,16 +86,17 @@ def api_error_handler(func):
     except AuthenticationRequired, e:
       response['status'] = 401
     except ValidationError, e:
+      LOG.exception('Error validation %s' % func)
       response['status'] = -1
       response['message'] = e.message
     except QueryError, e:
-      LOG.exception('error running %s' % func)
+      LOG.exception('Error running %s' % func)
       response['status'] = 1
       response['message'] = force_unicode(str(e))
       if e.handle:
         response['handle'] = e.handle
     except Exception, e:
-      LOG.exception('error running %s' % func)
+      LOG.exception('Error running %s' % func)
       response['status'] = -1
       response['message'] = force_unicode(str(e))
     finally:

+ 16 - 5
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -655,7 +655,7 @@
             self.status('success');
             self.progress(100);
           } else {
-            self.checkStatus();
+            if (! notebook.unloaded()) { self.checkStatus(); };
           }
         } else {
           self._ajaxError(data, self.execute);
@@ -864,7 +864,7 @@
 
           if (self.status() == 'running' || self.status() == 'starting') {
             self.result.endTime(new Date());
-            self.checkStatusTimeout = setTimeout(self.checkStatus, 1000);
+            if (! notebook.unloaded()) { self.checkStatusTimeout = setTimeout(self.checkStatus, 1000); };
           }
           else if (self.status() == 'available') {
             self.fetchResult(100);
@@ -1091,6 +1091,17 @@
       });
     };
 
+    self.unloaded = ko.observable(false);
+    self.unload = function() {
+      self.unloaded(true);
+      self.snippets().forEach(function(snippet){
+        if (snippet.checkStatusTimeout != null) {
+          clearTimeout(snippet.checkStatusTimeout);
+          snippet.checkStatusTimeout = null;
+        }
+      });
+    }
+
     self.restartSession = function (session, callback) {
       if (session.restarting()) {
         return;
@@ -1661,10 +1672,10 @@
     };
 
     self.loadNotebook = function (notebook, queryTab) {
-      if (self.checkStatusTimeout != null) {
-        clearTimeout(self.checkStatusTimeout);
-        self.checkStatusTimeout = null;
+      if (self.selectedNotebook() != null) {
+        self.selectedNotebook().unload();
       }
+
       var notebook = new Notebook(self, notebook);
       if (notebook.snippets().length > 0) {
         notebook.selectedSnippet(notebook.snippets()[notebook.snippets().length - 1].type());