瀏覽代碼

HUE-3554 [editor] Prevent history dates of 46 years

Romain Rigaux 9 年之前
父節點
當前提交
cf14b2f

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

@@ -301,6 +301,7 @@ def get_history(request):
   response = {'status': -1}
 
   doc_type = request.GET.get('doc_type')
+  limit = max(request.GET.get('len', 50), 100)
 
   response['status'] = 0
   response['history'] = [{
@@ -308,8 +309,8 @@ def get_history(request):
       'id': doc.id,
       'uuid': doc.uuid,
       'data': Notebook(document=doc).get_data(),
-      'absoluteUrl': doc.get_absolute_url()
-      } for doc in Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user).order_by('-last_modified')[:25]]
+      'absoluteUrl': doc.get_absolute_url(),
+      } for doc in Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user).order_by('-last_modified')[:limit]]
   response['message'] = _('History fetched')
 
   return JsonResponse(response)

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

@@ -240,7 +240,7 @@
           self.queriesHasErrors(true);
         },
         page: self.queriesCurrentPage(),
-        limit: 25,
+        limit: 50,
         type: 'query-' + self.type()
       });
     }
@@ -537,11 +537,11 @@
       }
     };
 
-    self.lastExecuted = 0;
+    self.lastExecuted = ko.observable(typeof snippet.lastExecuted != "undefined" && snippet.lastExecuted != null ? snippet.lastExecuted : 0);
 
     self.execute = function () {
       var now = (new Date()).getTime(); // We don't allow fast clicks
-      if (self.status() == 'running' || self.status() == 'loading' || now - self.lastExecuted < 1000 || self.statement() == '') {
+      if (self.status() == 'running' || self.status() == 'loading' || now - self.lastExecuted() < 1000 || self.statement() == '') {
         return;
       }
 
@@ -555,7 +555,7 @@
         chartYMulti: typeof self.chartYMulti() !== "undefined" ? self.chartYMulti() : self.previousChartOptions.chartYMulti
       };
       $(document).trigger("executeStarted", self);
-      self.lastExecuted = now;
+      self.lastExecuted(now);
       $(".jHueNotify").hide();
       logGA('execute/' + self.type());
 
@@ -1256,7 +1256,8 @@
 
     self.fetchHistory = function () {
       $.get("/notebook/api/get_history", {
-        doc_type: self.selectedSnippet()
+        doc_type: self.selectedSnippet(),
+        limit: 50
       }, function(data) {
         var parsedHistory = [];
         if (data && data.history){