mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-22 16:58:49 +02:00
fix(ipam): Use bulk_update in VLANGroup VID range migration
Replace per-row `save()` calls with `bulk_update` when populating VLANGroup VLAN ID ranges during migration. This avoids triggering post_save handlers (e.g. search cache/indexing) on existing VLANGroup records and updates only the relevant fields, improving both reliability and performance on larger databases. Fixes #21375
This commit is contained in:
committed by
Jeremy Stretch
parent
ae736ef407
commit
f4c27fd494
@@ -13,10 +13,11 @@ def set_vid_ranges(apps, schema_editor):
|
|||||||
VLANGroup = apps.get_model('ipam', 'VLANGroup')
|
VLANGroup = apps.get_model('ipam', 'VLANGroup')
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
for group in VLANGroup.objects.using(db_alias).all():
|
vlan_groups = VLANGroup.objects.using(db_alias).only('id', 'min_vid', 'max_vid')
|
||||||
|
for group in vlan_groups:
|
||||||
group.vid_ranges = [NumericRange(group.min_vid, group.max_vid, bounds='[]')]
|
group.vid_ranges = [NumericRange(group.min_vid, group.max_vid, bounds='[]')]
|
||||||
group._total_vlan_ids = group.max_vid - group.min_vid + 1
|
group._total_vlan_ids = group.max_vid - group.min_vid + 1
|
||||||
group.save()
|
VLANGroup.objects.using(db_alias).bulk_update(vlan_groups, ['vid_ranges', '_total_vlan_ids'], batch_size=100)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|||||||
Reference in New Issue
Block a user