Skip to content

Commit

Permalink
Sort data before groupby in TIS duration calculation (#33535)
Browse files Browse the repository at this point in the history
(cherry picked from commit 79b8cfc)
  • Loading branch information
Taragolis authored and ephraimbuddy committed Aug 28, 2023
1 parent 42cfb91 commit 5101840
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3236,10 +3236,12 @@ def duration(self, dag_id: str, session: Session = NEW_SESSION):
if failed_task_instance.duration:
fails_totals[dict_key] += failed_task_instance.duration

# we must group any mapped TIs by dag_id, task_id, run_id
# We must group any mapped TIs by dag_id, task_id, run_id
def grouping_key(ti: TaskInstance):
return ti.dag_id, ti.task_id, ti.run_id

mapped_tis = set()
tis_grouped = itertools.groupby(task_instances, lambda x: (x.dag_id, x.task_id, x.run_id))
for _, group in tis_grouped:
for _, group in itertools.groupby(sorted(task_instances, key=grouping_key), key=grouping_key):
tis = list(group)
duration = sum(x.duration for x in tis if x.duration)
if duration:
Expand Down

0 comments on commit 5101840

Please sign in to comment.