Skip to content

Commit

Permalink
Fix segment count backfill migration to include non-waits
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 28, 2024
1 parent 9c32990 commit 4584a44
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions temba/flows/migrations/0345_backfill_segment_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,14 @@ def backfill_segment_counts(apps, schema_editor): # pragma: no cover
def backfill_for_flow(apps, flow) -> int: # pragma: no cover
FlowActivityCount = apps.get_model("flows", "FlowActivityCount")

# no waits then no engagement counts
exit_uuids = flow.metadata.get("waiting_exit_uuids", [])
if not exit_uuids:
return

exit_counts = flow.path_counts.filter(from_uuid__in=exit_uuids)

with transaction.atomic():
to_create = []

def add_count(scope: str, count: int):
if count > 0:
to_create.append(FlowActivityCount(flow=flow, scope=scope, count=count, is_squashed=True))

by_segment = exit_counts.values("from_uuid", "to_uuid").annotate(total=Sum("count"))
by_segment = flow.path_counts.values("from_uuid", "to_uuid").annotate(total=Sum("count"))
for count in by_segment:
add_count(f"segment:{count['from_uuid']}:{count['to_uuid']}", count["total"])

Expand Down

0 comments on commit 4584a44

Please sign in to comment.