ashb commented on a change in pull request #7492: [AIRFLOW-6871] optimize tree 
view for large DAGs
URL: https://github.com/apache/airflow/pull/7492#discussion_r384171265
 
 

 ##########
 File path: airflow/www/templates/airflow/tree.html
 ##########
 @@ -85,8 +85,59 @@
 <script>
 $('span.status_square').tooltip({html: true});
 
+function ts_to_dtstr(ts) {
+  var dt = new Date(ts * 1000);
+  return dt.toISOString();
+}
+
+function is_dag_run(d) {
+  return d.run_id !== undefined;
+}
+
+var now_ts = Date.now()/1000;
+
+function populate_taskinstance_properties(node) {
+  // populate task instance properties for display purpose
+  var j;
+  for (j=0; j<node.instances.length; j++) {
+    var dr_instance = data.instances[j];
+    var row = node.instances[j];
+
+    if (row === null) {
+      node.instances[j] = {
+        task_id: node.name,
+        execution_date: dr_instance.execution_date,
+      };
+      continue;
+    }
+
+    var task_instance = {
+      state: row[0],
+      try_number: row[1],
+      start_ts: row[2],
+      duration: row[3],
+    };
+    node.instances[j] = task_instance;
+
+    task_instance.task_id = node.name;
+    task_instance.execution_date = dr_instance.execution_date;
+    task_instance.external_trigger = dr_instance.external_trigger;
+
+    // compute start_date and end_date if applicable
+    if (task_instance.start_ts !== null) {
+      task_instance.start_date = ts_to_dtstr(task_instance.start_ts);
+      if (task_instance.state === "running") {
+        task_instance.duration = now_ts - task_instance.start_ts;
+      } else if (task_instance.duration !== null) {
+        task_instance.end_date = ts_to_dtstr(task_instance.start_ts + 
task_instance.duration);
+      }
+    }
+  }
+}
+
 var devicePixelRatio = window.devicePixelRatio || 1;
-var data = {{ data|tojson|safe }};
+// JSON.parse is faster for large payloads than an object literal (because the 
JSON grammer is simpler!)
+var data = JSON.parse('{{ data|safe }}');
 
 Review comment:
   Use `from jinja2.utils import htmlsafe_json_dumps` in the view, and remove 
the `| safe` here in the template (The htmlsafe_json_dumps marks it as safe 
correctly, so we don't need it in the template)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to