浏览代码

HUE-7464 [editor] Do not save SQL sessions as they become stale

Does not impact query execution, but render wrong the currently listed session
of a saved query in the UI.
Romain Rigaux 8 年之前
父节点
当前提交
cffda11
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 1 1
      desktop/core/src/desktop/converter_tests.py
  2. 6 0
      desktop/libs/notebook/src/notebook/api.py

+ 1 - 1
desktop/core/src/desktop/converter_tests.py

@@ -135,7 +135,7 @@ class TestDocumentConverter(object):
       assert_equal(doch.last_modified.strftime('%Y-%m-%dT%H:%M:%S'), doc2.last_modified.strftime('%Y-%m-%dT%H:%M:%S'))
       assert_equal(doch.last_modified.strftime('%Y-%m-%dT%H:%M:%S'), doc2.last_modified.strftime('%Y-%m-%dT%H:%M:%S'))
 
 
       # Verify session type
       # Verify session type
-      assert_equal('hive', doc2.data_dict['sessions'][0]['type'])
+      assert_false(doc2.data_dict['sessions'])
 
 
       # Verify snippet values
       # Verify snippet values
       assert_equal('ready', doc2.data_dict['snippets'][0]['status'])
       assert_equal('ready', doc2.data_dict['snippets'][0]['status'])

+ 6 - 0
desktop/libs/notebook/src/notebook/api.py

@@ -330,6 +330,7 @@ def _save_notebook(notebook, user):
   notebook['isSaved'] = True
   notebook['isSaved'] = True
   notebook['isHistory'] = False
   notebook['isHistory'] = False
   notebook['id'] = notebook_doc.id
   notebook['id'] = notebook_doc.id
+  _clear_sessions(notebook)
   notebook_doc1 = notebook_doc._get_doc1(doc2_type=notebook_type)
   notebook_doc1 = notebook_doc._get_doc1(doc2_type=notebook_type)
   notebook_doc.update_data(notebook)
   notebook_doc.update_data(notebook)
   notebook_doc.search = _get_statement(notebook)
   notebook_doc.search = _get_statement(notebook)
@@ -359,6 +360,10 @@ def save_notebook(request):
   return JsonResponse(response)
   return JsonResponse(response)
 
 
 
 
+def _clear_sessions(notebook):
+  notebook['sessions'] = [_s for _s in notebook['sessions'] if _s['type'] in ('scala', 'spark', 'pyspark', 'sparkr')]
+
+
 def _historify(notebook, user):
 def _historify(notebook, user):
   query_type = notebook['type']
   query_type = notebook['type']
   name = notebook['name'] if (notebook['name'] and notebook['name'].strip() != '') else DEFAULT_HISTORY_NAME
   name = notebook['name'] if (notebook['name'] and notebook['name'].strip() != '') else DEFAULT_HISTORY_NAME
@@ -391,6 +396,7 @@ def _historify(notebook, user):
     )
     )
 
 
   notebook['uuid'] = history_doc.uuid
   notebook['uuid'] = history_doc.uuid
+  _clear_sessions(notebook)
   history_doc.update_data(notebook)
   history_doc.update_data(notebook)
   history_doc.search = _get_statement(notebook)
   history_doc.search = _get_statement(notebook)
   history_doc.save()
   history_doc.save()