You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bb...@apache.org on 2022/04/07 15:30:58 UTC

[airflow] 01/01: Remove extraneous json parsing

This is an automated email from the ASF dual-hosted git repository.

bbovenzi pushed a commit to branch remove-extra-json-parse
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 7197af97e5bdcec5547e3cc0f15b6ddb21114259
Author: Brent Bovenzi <br...@gmail.com>
AuthorDate: Thu Apr 7 11:19:01 2022 -0400

    Remove extraneous json parsing
---
 airflow/www/static/js/calendar.js           | 9 +++------
 airflow/www/templates/airflow/calendar.html | 2 +-
 airflow/www/templates/airflow/tree.html     | 3 ++-
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/airflow/www/static/js/calendar.js b/airflow/www/static/js/calendar.js
index bb4b6e73cf..54ed93d3dd 100644
--- a/airflow/www/static/js/calendar.js
+++ b/airflow/www/static/js/calendar.js
@@ -63,9 +63,6 @@ const dateFormat = 'YYYY-MM-DD';
 document.addEventListener('DOMContentLoaded', () => {
   $('span.status_square').tooltip({ html: true });
 
-  // JSON.parse is faster for large payloads than an object literal
-  const rootData = JSON.parse(calendarData);
-
   const dayTip = d3.tip()
     .attr('class', 'tooltip d3-tip')
     .html((toolTipHtml) => toolTipHtml);
@@ -93,12 +90,12 @@ document.addEventListener('DOMContentLoaded', () => {
       .key((dr) => moment.utc(dr.date, dateFormat).month())
       .key((dr) => moment.utc(dr.date, dateFormat).date())
       .key((dr) => dr.state)
-      .map(rootData.dag_states);
+      .map(calendarData.dag_states);
 
     // Make sure we have one year displayed for each year between the start and end dates.
     // This also ensures we do not have show an empty calendar view when no dag runs exist.
-    const startYear = moment.utc(rootData.start_date, dateFormat).year();
-    const endYear = moment.utc(rootData.end_date, dateFormat).year();
+    const startYear = moment.utc(calendarData.start_date, dateFormat).year();
+    const endYear = moment.utc(calendarData.end_date, dateFormat).year();
     for (let y = startYear; y <= endYear; y += 1) {
       dagStates[y] = dagStates[y] || {};
     }
diff --git a/airflow/www/templates/airflow/calendar.html b/airflow/www/templates/airflow/calendar.html
index 719adcee5a..be8c98115c 100644
--- a/airflow/www/templates/airflow/calendar.html
+++ b/airflow/www/templates/airflow/calendar.html
@@ -51,6 +51,6 @@
       statesColors["{{state}}"] = "{{state_color_mapping[state]}}";
     {% endfor %}
 
-    const calendarData = {{ data|tojson }};
+    const calendarData = {{ data }};
   </script>
 {% endblock %}
diff --git a/airflow/www/templates/airflow/tree.html b/airflow/www/templates/airflow/tree.html
index 1394cbc61b..4011fff4d5 100644
--- a/airflow/www/templates/airflow/tree.html
+++ b/airflow/www/templates/airflow/tree.html
@@ -78,7 +78,8 @@
 {% block tail_js %}
   {{ super() }}
   <script>
-    const treeData = {{ data|tojson }};
+    // Data is already json, there is no need to convert it
+    const treeData = {{ data }};
     const stateColors = {{ state_color_mapping|tojson }};
     const autoRefreshInterval = {{ auto_refresh_interval }};
   </script>