perf: migrations automationexecution type

pull/15037/head
wangruidong 2025-03-14 14:45:15 +08:00 committed by w940853815
parent 94e8c62953
commit f513eb62a6
1 changed files with 19 additions and 8 deletions

View File

@ -1,16 +1,27 @@
# Generated by Django 4.1.13 on 2025-03-13 09:14 # Generated by Django 4.1.13 on 2025-03-13 09:14
import time
from django.db import migrations, models from django.db import migrations, models
def migrate_execution_type(apps, schema_editor): def migrate_execution_type(apps, schema_editor):
execution_model = apps.get_model('assets', 'AutomationExecution') count = 0
execution_objs = [] bulk_size = 1000
for execution in execution_model.objects.all(): while True:
snapshot = execution.snapshot start = time.time()
execution.type = snapshot.get('type', '') execution_model = apps.get_model('assets', 'AutomationExecution')
execution_objs.append(execution) execution_objs = []
execution_model.objects.bulk_update(execution_objs, ['type']) executions = execution_model.objects.all()[count:count + bulk_size]
if not executions:
break
for execution in executions:
snapshot = execution.snapshot
execution.type = snapshot.get('type', '')
execution_objs.append(execution)
execution_model.objects.bulk_update(execution_objs, ['type'])
print("\tUpdate rexecutions: {}-{} using: {:.2f}s".format(
count, count + len(executions), time.time() - start
))
count += len(executions)
class Migration(migrations.Migration): class Migration(migrations.Migration):