1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Specify batch size for bulk_update()

This commit is contained in:
jeremystretch
2021-05-27 15:25:40 -04:00
parent d34b9ee00e
commit 88aa3a4e19

View File

@ -13,7 +13,7 @@ def update_parents_children(prefix):
parents = prefix.get_parents(include_self=True).annotate_hierarchy()
for parent in parents:
parent._children = parent.hierarchy_children
Prefix.objects.bulk_update(parents, ['_children'])
Prefix.objects.bulk_update(parents, ['_children'], batch_size=100)
def update_children_depth(prefix):
@ -23,7 +23,7 @@ def update_children_depth(prefix):
children = prefix.get_children(include_self=True).annotate_hierarchy()
for child in children:
child._depth = child.hierarchy_depth
Prefix.objects.bulk_update(children, ['_depth'])
Prefix.objects.bulk_update(children, ['_depth'], batch_size=100)
@receiver(post_save, sender=Prefix)