Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
[AIRFLOW-6268] Prevent ajax calls when no dags (apache#6839)
Browse files Browse the repository at this point in the history
Prevent 4 AJAX calls on empty search result page of DAGs view.
  • Loading branch information
robinedwards authored and galuszkak committed Mar 5, 2020
1 parent 720754f commit 01f41b9
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions airflow/www/templates/airflow/dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ <h2>DAGs</h2>
<th>Owner</th>
<th style="padding-left: 5px;">Recent Tasks
<span id="statuses_info" class="glyphicon glyphicon-info-sign" aria-hidden="true" title="Status of tasks from all active DAG runs or, if not currently active, from most recent run."></span>
<img id="loading" width="15" src="{{ url_for("static", filename="loading.gif") }}">
<img class="loading-task-stats" width="15" src="{{ url_for("static", filename="loading.gif") }}">
</th>
<th style="padding-left: 5px;">Last Run <span id="statuses_info" class="glyphicon glyphicon-info-sign" aria-hidden="true" title="Execution Date/Time of Highest Dag Run."></span>
</th>
<th style="padding-left: 5px;">DAG Runs
<span id="statuses_info" class="glyphicon glyphicon-info-sign" aria-hidden="true" title="Status of all previous DAG runs."></span>
<img id="loading" width="15" src="{{ url_for("static", filename="loading.gif") }}">
<img class="loading-dag-stats" width="15" src="{{ url_for("static", filename="loading.gif") }}">
</th>
<th class="text-center">Links</th>
</tr>
Expand Down Expand Up @@ -303,7 +303,8 @@ <h2>DAGs</h2>
circle_margin = 4;
stroke_width = 2;
stroke_width_hover = 6;
d3.json("{{ url_for('Airflow.blocked') }}", function(error, json) {

function blockedHandler(error, json) {
$.each(json, function() {
$('.label.schedule.' + this.dag_id)
.attr('title', this.active_dag_run + '/' + this.max_active_runs + ' active dag runs')
Expand All @@ -313,8 +314,9 @@ <h2>DAGs</h2>
.css('background-color', 'red');
}
});
});
d3.json("{{ url_for('Airflow.last_dagruns') }}?dag_ids=" + (encoded_dag_ids.join(',')), function(error, json) {
}

function lastDagRunsHandler(error, json) {
for(var safe_dag_id in json) {
dag_id = json[safe_dag_id].dag_id;
last_run = json[safe_dag_id].last_run;
Expand All @@ -328,8 +330,9 @@ <h2>DAGs</h2>
g.selectAll(".loading-last-run").remove();
}
d3.selectAll(".loading-last-run").remove();
});
d3.json("{{ url_for('Airflow.dag_stats') }}?dag_ids=" + (encoded_dag_ids.join(',')), function(error, json) {
}

function dagStatsHandler(error, json) {
for(var dag_id in json) {
states = json[dag_id];
g = d3.select('svg#dag-run-' + dag_id.replace(/\./g, '__dot__'))
Expand Down Expand Up @@ -398,7 +401,7 @@ <h2>DAGs</h2>
.duration(500)
.delay(function(d, i){return i*50;})
.style("opacity", 1);
d3.select("#loading").remove();
d3.select(".loading-dag-stats").remove();
}
$("#pause_header").tooltip();
$("#statuses_info").tooltip();
Expand All @@ -407,8 +410,9 @@ <h2>DAGs</h2>
html: true,
container: "body",
});
});
d3.json("{{ url_for('Airflow.task_stats') }}?dag_ids=" + (encoded_dag_ids.join(',')), function(error, json) {
}

function taskStatsHandler(error, json) {
for(var dag_id in json) {
states = json[dag_id];
g = d3.select('svg#task-run-' + dag_id.replace(/\./g, '__dot__'))
Expand Down Expand Up @@ -477,7 +481,7 @@ <h2>DAGs</h2>
.duration(500)
.delay(function(d, i){return i*50;})
.style("opacity", 1);
d3.select("#loading").remove();
d3.select(".loading-task-stats").remove();
}
$("#pause_header").tooltip();
$("#statuses_info").tooltip();
Expand All @@ -486,6 +490,20 @@ <h2>DAGs</h2>
html: true,
container: "body",
});
});
}

if (encoded_dag_ids.length > 0) {
// dags on page fetch stats
d3.json("{{ url_for('Airflow.blocked') }}", blockedHandler);
d3.json("{{ url_for('Airflow.last_dagruns') }}?dag_ids=" + (encoded_dag_ids.join(',')), lastDagRunsHandler);
d3.json("{{ url_for('Airflow.dag_stats') }}?dag_ids=" + (encoded_dag_ids.join(',')), dagStatsHandler);
d3.json("{{ url_for('Airflow.task_stats') }}?dag_ids=" + (encoded_dag_ids.join(',')), taskStatsHandler);
}
else {
// no dags, hide the loading gifs
$(".loading-task-stats").remove();
$(".loading-dag-stats").remove();
}

</script>
{% endblock %}

0 comments on commit 01f41b9

Please sign in to comment.