@@ -0,0 +1,1359 @@
+# -*- coding: utf-8 -*-%0A# Generated by Django 1.10.5 on 2017-03-30 12:50%0Afrom __future__ import unicode_literals%0A%0Afrom django.db import migrations%0A%0A%0Adef do_populate(FlowStep, FlowNodeCount):%0A    nodes = list(FlowStep.objects.filter(left_on=None, run__is_active=True).distinct('step_uuid').values_list('run__flow_id', 'step_uuid'))%0A%0A    if nodes:%0A        print(%22Fetched %25d node UUIDs with active contacts%22 %25 len(nodes))%0A%0A    counts = %5B%5D%0A    for flow_id, node_uuid in nodes:%0A        contact_count = FlowStep.objects.filter(step_uuid=node_uuid, left_on=None, run__is_active=True).count()%0A%0A        FlowNodeCount.objects.filter(flow_id=flow_id, node_uuid=node_uuid).delete()%0A        counts.append(FlowNodeCount(flow_id=flow_id, node_uuid=node_uuid, count=contact_count))%0A%0A    FlowNodeCount.objects.bulk_create(counts, batch_size=5000)%0A%0A%0Adef populate_flownodecount(apps, schema_editor):%0A    FlowStep = apps.get_model('flows', 'FlowStep')%0A    FlowNodeCount = apps.get_model('flows', 'FlowNodeCount')%0A%0A    do_populate(FlowStep, FlowNodeCount)%0A%0A%0Adef apply_manual():%0A    from temba.flows.models import FlowStep, FlowNodeCount%0A%0A    do_populate(FlowStep, FlowNodeCount)%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('flows', '0095_clear_old_flow_stat_cache'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(populate_flownodecount)%0A    %5D%0A

Add migration to populate FlowNodeCount