Skip to content

Commit

Permalink
Optimize calendar view for cron scheduled DAGs (apache#24262)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedcunningham authored Jun 9, 2022
1 parent 85c247a commit 23fb663
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import warnings
from bisect import insort_left
from collections import defaultdict
from datetime import timedelta
from datetime import datetime, timedelta
from functools import wraps
from json import JSONDecodeError
from operator import itemgetter
Expand All @@ -39,6 +39,7 @@
import markupsafe
import nvd3
import sqlalchemy as sqla
from croniter import croniter
from flask import (
Response,
abort,
Expand Down Expand Up @@ -117,6 +118,7 @@
from airflow.ti_deps.dep_context import DepContext
from airflow.ti_deps.dependencies_deps import RUNNING_DEPS, SCHEDULER_QUEUED_DEPS
from airflow.timetables.base import DataInterval, TimeRestriction
from airflow.timetables.interval import CronDataIntervalTimetable
from airflow.utils import json as utils_json, timezone, yaml
from airflow.utils.dates import infer_time_unit, scale_time_units
from airflow.utils.docs import get_doc_url_for_provider, get_docs_url
Expand Down Expand Up @@ -2742,18 +2744,28 @@ def _convert_to_date(session, column):
restriction = TimeRestriction(dag.start_date, dag.end_date, False)
dates = collections.Counter()

while True:
info = dag.timetable.next_dagrun_info(
last_automated_data_interval=last_automated_data_interval, restriction=restriction
)
if info is None:
break

if info.logical_date.year != year:
break

last_automated_data_interval = info.data_interval
dates[info.logical_date] += 1
if isinstance(dag.timetable, CronDataIntervalTimetable):
for next in croniter(
dag.timetable.summary, start_time=last_automated_data_interval.end, ret_type=datetime
):
if next is None:
break
if next.year != year:
break
if dag.end_date and next > dag.end_date:
break
dates[next.date()] += 1
else:
while True:
info = dag.timetable.next_dagrun_info(
last_automated_data_interval=last_automated_data_interval, restriction=restriction
)
if info is None:
break
if info.logical_date.year != year:
break
last_automated_data_interval = info.data_interval
dates[info.logical_date] += 1

data_dag_states.extend(
{'date': date.isoformat(), 'state': 'planned', 'count': count}
Expand Down

0 comments on commit 23fb663

Please sign in to comment.