Optimize bulk updates of custom field values when custom fields are added/removed #18980
Labels
complexity: medium
Requires a substantial but not unusual amount of effort to implement
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
Milestone
NetBox version
v4.2.5
Feature type
Change to existing functionality
Proposed functionality
This FR intends to capture an opportunity to improve performance when a custom field is added to or removed from a model which has many thousands of records. Whenever a custom field is added, its
populate_initial_data()
method is called to automatically populate the field's default value on all objects:netbox/netbox/extras/models/customfields.py
Lines 279 to 289 in 7db0765
The current approach is suboptimal, as it requires loading each individual object into memory to effect the change. I believe we can optimize this by mutating the JSON data directly within the query:
This allows us to update the value of a specific key for all objects without first loading each into memory.
Similar approaches will be needed for the
remove_stale_data()
andrename_object_data()
methods on CustomField as well.Use case
This should result in a dramatic reduction in the time required to bulk update custom field data, particularly when many thousands of records are affected.
Database changes
N/A
External dependencies
N/A
The text was updated successfully, but these errors were encountered: