Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize calendar view for cron scheduled DAGs #24262

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2740,18 +2742,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