mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
Specify batch size for cached counter migrations
This commit is contained in:
parent
065a40dfb3
commit
99140a9413
@ -6,7 +6,7 @@ import utilities.fields
|
||||
|
||||
def recalculate_device_counts(apps, schema_editor):
|
||||
Device = apps.get_model("dcim", "Device")
|
||||
devices = list(Device.objects.all().annotate(
|
||||
devices = Device.objects.annotate(
|
||||
_console_port_count=Count('consoleports', distinct=True),
|
||||
_console_server_port_count=Count('consoleserverports', distinct=True),
|
||||
_power_port_count=Count('powerports', distinct=True),
|
||||
@ -17,7 +17,7 @@ def recalculate_device_counts(apps, schema_editor):
|
||||
_device_bay_count=Count('devicebays', distinct=True),
|
||||
_module_bay_count=Count('modulebays', distinct=True),
|
||||
_inventory_item_count=Count('inventoryitems', distinct=True),
|
||||
))
|
||||
)
|
||||
|
||||
for device in devices:
|
||||
device.console_port_count = device._console_port_count
|
||||
@ -42,7 +42,7 @@ def recalculate_device_counts(apps, schema_editor):
|
||||
'device_bay_count',
|
||||
'module_bay_count',
|
||||
'inventory_item_count',
|
||||
])
|
||||
], batch_size=100)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -12,7 +12,7 @@ def populate_virtualchassis_members(apps, schema_editor):
|
||||
for vc in vcs:
|
||||
vc.member_count = vc._member_count
|
||||
|
||||
VirtualChassis.objects.bulk_update(vcs, ['member_count'])
|
||||
VirtualChassis.objects.bulk_update(vcs, ['member_count'], batch_size=100)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -12,7 +12,7 @@ def populate_virtualmachine_counts(apps, schema_editor):
|
||||
for vm in vms:
|
||||
vm.interface_count = vm._interface_count
|
||||
|
||||
VirtualMachine.objects.bulk_update(vms, ['interface_count'])
|
||||
VirtualMachine.objects.bulk_update(vms, ['interface_count'], batch_size=100)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
Loading…
Reference in New Issue
Block a user