This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 5db245d5c7fe22e2248e1d3103ed1a34a5dfa526 Author: Kamil BreguĊa <[email protected]> AuthorDate: Wed May 6 18:33:12 2020 +0200 Optimize count query on /home (#8729) --- airflow/www_rbac/views.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/airflow/www_rbac/views.py b/airflow/www_rbac/views.py index 6ae6ef6..c7831c4 100644 --- a/airflow/www_rbac/views.py +++ b/airflow/www_rbac/views.py @@ -289,12 +289,22 @@ class Airflow(AirflowBaseView): active_dags = dags_query.filter(~DagModel.is_paused) paused_dags = dags_query.filter(DagModel.is_paused) + is_paused_count = dict( + all_dags.with_entities(DagModel.is_paused, func.count(DagModel.dag_id)) + .group_by(DagModel.is_paused).all() + ) + status_count_active = is_paused_count.get(False, 0) + status_count_paused = is_paused_count.get(True, 0) + all_dags_count = status_count_active + status_count_paused if arg_status_filter == 'active': current_dags = active_dags + num_of_all_dags = status_count_active elif arg_status_filter == 'paused': current_dags = paused_dags + num_of_all_dags = status_count_paused else: current_dags = all_dags + num_of_all_dags = all_dags_count dags = current_dags.order_by(DagModel.dag_id).options( joinedload(DagModel.tags)).offset(start).limit(dags_per_page).all() @@ -320,13 +330,8 @@ class Airflow(AirflowBaseView): filename=filename), "error") - num_of_all_dags = current_dags.count() num_of_pages = int(math.ceil(num_of_all_dags / float(dags_per_page))) - status_count_active = active_dags.count() - status_count_paused = paused_dags.count() - status_count_all = status_count_active + status_count_paused - return self.render_template( 'airflow/dags.html', dags=dags, @@ -344,7 +349,7 @@ class Airflow(AirflowBaseView): num_runs=num_runs, tags=tags, status_filter=arg_status_filter, - status_count_all=status_count_all, + status_count_all=all_dags_count, status_count_active=status_count_active, status_count_paused=status_count_paused)
