-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox Version
v4.5.1
Python Version
3.12
Area(s) of Concern
- User Interface
- REST API
- GraphQL API
- Python ORM
- Other
Details
Currently, an ObjectChange record is created in the database immediately after save() is called on an applicable model. This results in each record being created individually even for bulk operations.
We should enqueue the creation of change records until all changes have been successfully applied, and write them to the database via a single bulk operation immediately prior to the transaction being committed. This optimizes the creation of change records into a single bulk SQL INSERT.
We'll need to identify a solution which leverages a queue when changes are made in the context of a request, but retains the current synchronous behavior (via post_save) otherwise.
While it would be feasible to defer the creation of change records to an async background task, we should keep them constrained to the same database transaction in which the changes are applied. This ensures that the both the application and logging of a change to an object are atomic.