Skip to content

Defer change logging until all changes have been applied #21336

@jeremystretch

Description

@jeremystretch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    netboxstatus: needs triageThis issue is awaiting triage by a maintainertype: performanceA concern regarding application performance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions