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

Fix and speed up grid view #23947

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
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
57 changes: 28 additions & 29 deletions airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,39 +128,38 @@ def get_mapped_summary(parent_instance, task_instances):
}


def get_task_summary(dag_run: DagRun, task, session: Session) -> Optional[Dict[str, Any]]:
task_instance = (
session.query(TaskInstance)
.filter(
TaskInstance.dag_id == task.dag_id,
TaskInstance.run_id == dag_run.run_id,
TaskInstance.task_id == task.task_id,
# Only get normal task instances or the first mapped task
TaskInstance.map_index <= 0,
)
.first()
def get_task_summaries(task, dag_runs: List[DagRun], session: Session) -> List[Dict[str, Any]]:
tis = session.query(TaskInstance).filter(
TaskInstance.dag_id == task.dag_id,
TaskInstance.run_id.in_([dag_run.run_id for dag_run in dag_runs]),
TaskInstance.task_id == task.task_id,
# Only get normal task instances or the first mapped task
TaskInstance.map_index <= 0,
)

if not task_instance:
return None
def _get_summary(task_instance):
if task_instance.map_index > -1:
return get_mapped_summary(
task_instance, task_instances=get_mapped_instances(task_instance, session)
)

if task_instance.map_index > -1:
return get_mapped_summary(task_instance, task_instances=get_mapped_instances(task_instance, session))
try_count = (
task_instance.prev_attempted_tries
if task_instance.prev_attempted_tries != 0
else task_instance.try_number
)

try_count = (
task_instance.prev_attempted_tries
if task_instance.prev_attempted_tries != 0
else task_instance.try_number
)
return {
'task_id': task_instance.task_id,
'run_id': task_instance.run_id,
'map_index': task_instance.map_index,
'state': task_instance.state,
'start_date': datetime_to_string(task_instance.start_date),
'end_date': datetime_to_string(task_instance.end_date),
'try_number': try_count,
}
return {
'task_id': task_instance.task_id,
'run_id': task_instance.run_id,
'map_index': task_instance.map_index,
'state': task_instance.state,
'start_date': datetime_to_string(task_instance.start_date),
'end_date': datetime_to_string(task_instance.end_date),
'try_number': try_count,
}

return [_get_summary(ti) for ti in tis]


def encode_dag_run(dag_run: Optional[models.DagRun]) -> Optional[Dict[str, Any]]:
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def task_group_to_grid(task_item_or_group, dag, dag_runs, session):
if isinstance(task_item_or_group, AbstractOperator):
return {
'id': task_item_or_group.task_id,
'instances': [wwwutils.get_task_summary(dr, task_item_or_group, session) for dr in dag_runs],
'instances': wwwutils.get_task_summaries(task_item_or_group, dag_runs, session),
'label': task_item_or_group.label,
'extra_links': task_item_or_group.extra_links,
'is_mapped': task_item_or_group.is_mapped,
Expand Down