Skip to content

Commit 7c708e8

Browse files
committed
Use bulk_update() to speed up VCID migration #811
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 2a70836 commit 7c708e8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

vulnerabilities/migrations/0023_vcid_migration.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ class Migration(migrations.Migration):
1212

1313
def save_vulnerability_id(apps, schema_editor):
1414
Vulnerabilities = apps.get_model("vulnerabilities", "Vulnerability")
15+
updatables = []
1516
for vulnerability in Vulnerabilities.objects.filter(~Q(vulnerability_id__startswith="VCID-")):
1617
vulnerability.vulnerability_id = build_vcid()
17-
vulnerability.save()
18+
updatables.append(vulnerability)
19+
# update in bulk, 500 at a time
20+
updated = Vulnerabilities.objects.bulk_update(
21+
objs=updatables,
22+
fields=["vulnerability_id"],
23+
batch_size=500,
24+
)
25+
print(f"Migrated {updated} vulnerabilities to new VCID")
1826

1927
operations = [
2028
migrations.RunPython(save_vulnerability_id, migrations.RunPython.noop)

0 commit comments

Comments
 (0)