Pārlūkot izejas kodu

HUE-3643 [editor] Lighter payload when fetching the history

Coming from tens of MB to just a few KBs for the same result.
Romain Rigaux 9 gadi atpakaļ
vecāks
revīzija
a9fd93a

+ 18 - 7
desktop/libs/notebook/src/notebook/api.py

@@ -306,13 +306,24 @@ def get_history(request):
   limit = max(request.GET.get('len', 50), 100)
 
   response['status'] = 0
-  response['history'] = [{
-      'name': doc.name,
-      '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')[:limit]]
+  history = []
+  for doc in Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user).order_by('-last_modified')[:limit]:
+    notebook = Notebook(document=doc).get_data()
+    if 'snippets' in notebook:
+      history.append({
+        'name': doc.name,
+        'id': doc.id,
+        'uuid': doc.uuid,
+        'data': {
+            'statement_raw': notebook['snippets'][0]['statement_raw'][:1001],
+            'lastExecuted':  notebook['snippets'][0]['lastExecuted'],
+            'status':  notebook['snippets'][0]['status']
+        },
+        'absoluteUrl': doc.get_absolute_url(),
+      })
+    else:
+      LOG.error('Incomplete History Notebook: %s' % notebook)
+  response['history'] = history
   response['message'] = _('History fetched')
 
   return JsonResponse(response)

+ 3 - 3
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1295,9 +1295,9 @@
             parsedHistory.push(
               self._makeHistoryRecord(
                 nbk.absoluteUrl,
-                nbk.data.snippets[0].statement_raw,
-                nbk.data.snippets[0].lastExecuted,
-                nbk.data.snippets[0].status,
+                nbk.data.statement_raw,
+                nbk.data.lastExecuted,
+                nbk.data.status,
                 nbk.uuid
               )
             );