Repository: incubator-airflow
Updated Branches:
  refs/heads/master 2fa155fe8 -> f7f585a89


[AIRFLOW-1656] Tree view dags query changed

[AIRFLOW-1656] Tree view query changes

Closes #3427 from djo10/master


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/f7f585a8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/f7f585a8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/f7f585a8

Branch: refs/heads/master
Commit: f7f585a897982cda5199aeee07b86476f9357196
Parents: 2fa155f
Author: djordje <[email protected]>
Authored: Fri Jun 15 12:30:06 2018 +0200
Committer: Fokko Driesprong <[email protected]>
Committed: Fri Jun 15 12:30:06 2018 +0200

----------------------------------------------------------------------
 airflow/models.py         |  3 ++-
 airflow/www/views.py      | 17 ++++++-----------
 airflow/www_rbac/views.py | 18 +++++++-----------
 3 files changed, 15 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/f7f585a8/airflow/models.py
----------------------------------------------------------------------
diff --git a/airflow/models.py b/airflow/models.py
index 704dc80..cef6efc 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -3622,7 +3622,8 @@ class DAG(BaseDag, LoggingMixin):
         TI = TaskInstance
         if not start_date:
             start_date = (timezone.utcnow() - timedelta(30)).date()
-            start_date = datetime.combine(start_date, datetime.min.time())
+            start_date = timezone.make_aware(
+                datetime.combine(start_date, datetime.min.time()))
         end_date = end_date or timezone.utcnow()
         tis = session.query(TI).filter(
             TI.dag_id == self.dag_id,

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/f7f585a8/airflow/www/views.py
----------------------------------------------------------------------
diff --git a/airflow/www/views.py b/airflow/www/views.py
index a16b685..8f6725e 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -1298,27 +1298,22 @@ class Airflow(BaseView):
         else:
             base_date = dag.latest_execution_date or timezone.utcnow()
 
-        dates = dag.date_range(base_date, num=-abs(num_runs))
-        min_date = dates[0] if dates else datetime(2000, 1, 1)
-
         DR = models.DagRun
         dag_runs = (
             session.query(DR)
-                .filter(
+            .filter(
                 DR.dag_id == dag.dag_id,
-                DR.execution_date <= base_date,
-                DR.execution_date >= min_date)
-                .all()
+                DR.execution_date <= base_date)
+            .order_by(DR.execution_date.desc())
+            .limit(num_runs)
+            .all()
         )
         dag_runs = {
             dr.execution_date: alchemy_to_dict(dr) for dr in dag_runs}
 
         dates = sorted(list(dag_runs.keys()))
-        # Only show the desired number of runs regardless of the trigger method
-        if len(dates) > num_runs:
-            dates = dates[-num_runs:]
-
         max_date = max(dates) if dates else None
+        min_date = min(dates) if dates else None
 
         tis = dag.get_task_instances(
             session, start_date=min_date, end_date=base_date)

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/f7f585a8/airflow/www_rbac/views.py
----------------------------------------------------------------------
diff --git a/airflow/www_rbac/views.py b/airflow/www_rbac/views.py
index 3a1951a..43e481e 100644
--- a/airflow/www_rbac/views.py
+++ b/airflow/www_rbac/views.py
@@ -976,26 +976,22 @@ class Airflow(AirflowBaseView):
         else:
             base_date = dag.latest_execution_date or timezone.utcnow()
 
-        dates = dag.date_range(base_date, num=-abs(num_runs))
-        min_date = dates[0] if dates else timezone.utc_epoch()
-
         DR = models.DagRun
         dag_runs = (
             session.query(DR)
-                   .filter(DR.dag_id == dag.dag_id, # noqa
-                           DR.execution_date <= base_date,
-                           DR.execution_date >= min_date)
-                   .all() # noqa
+            .filter(
+                DR.dag_id == dag.dag_id,
+                DR.execution_date <= base_date)
+            .order_by(DR.execution_date.desc())
+            .limit(num_runs)
+            .all()
         )
         dag_runs = {
             dr.execution_date: alchemy_to_dict(dr) for dr in dag_runs}
 
         dates = sorted(list(dag_runs.keys()))
-        # Only show the desired number of runs regardless of the trigger method
-        if len(dates) > num_runs:
-            dates = dates[-num_runs:]
-
         max_date = max(dates) if dates else None
+        min_date = min(dates) if dates else None
 
         tis = dag.get_task_instances(
             session, start_date=min_date, end_date=base_date)

Reply via email to