Pre-render and cache config context data #11946

Open
opened 2025-12-29 21:51:47 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Dec 22, 2025).

NetBox version

v4.4.8

Feature type

Data model extension

Proposed functionality

Currently, config context data is compiled for a device/VM on demand from the set of applicable ConfigContext instances that have been defined. In scenarios involving a large number of these instances, this can result in very complex, slow queries leading to long response times, as noted in #20358.

This FR proposes instead pre-calculating the config context data for all relevant objects (devices and VMs) via non-blocking background tasks whenever context data or devices/VMs are modified. This pre-rendered data could be cached locally on each device/VM to maximize query performance.

The primary challenge of this approach will be in reliably detecting all triggering changes. These include

  1. The creation, modification, or deletion of a ConfigContext object
  2. The creation or modification of a device/VM which impacts an associated ConfigContext object (e.g. changing the role of a device)

All updates to pre-rendered context data should be done via non-blocking asynchronous background jobs which are triggered after the relevant objects have been updated. Note that this does introduce a small window in which the rendered data for an object may be out of date. This could potentially be addressed by immediately nullifying the cached data whenever an update is queued, which would force an on-demand rendering of the context data for the object.

Use case

This approach shifts the delay of rendering config contexts to the background, optimizing for fast read queries and greatly reduced rendering times for device and VM config templates.

Database changes

A "private" nullable JSON field will likely be added to the Device and VirtualMachine models to store the pre-rendered config context data.

External dependencies

N/A

Originally created by @jeremystretch on GitHub (Dec 22, 2025). ### NetBox version v4.4.8 ### Feature type Data model extension ### Proposed functionality Currently, config context data is compiled for a device/VM on demand from the set of applicable ConfigContext instances that have been defined. In scenarios involving a large number of these instances, this can result in very complex, slow queries leading to long response times, as noted in #20358. This FR proposes instead pre-calculating the config context data for all relevant objects (devices and VMs) via non-blocking background tasks whenever context data or devices/VMs are modified. This pre-rendered data could be cached locally on each device/VM to maximize query performance. The primary challenge of this approach will be in reliably detecting all triggering changes. These include 1. The creation, modification, or deletion of a ConfigContext object 2. The creation or modification of a device/VM which impacts an associated ConfigContext object (e.g. changing the role of a device) All updates to pre-rendered context data should be done via non-blocking asynchronous background jobs which are triggered after the relevant objects have been updated. Note that this does introduce a small window in which the rendered data for an object may be out of date. This could potentially be addressed by immediately nullifying the cached data whenever an update is queued, which would force an on-demand rendering of the context data for the object. ### Use case This approach shifts the delay of rendering config contexts to the background, optimizing for fast read queries and greatly reduced rendering times for device and VM config templates. ### Database changes A "private" nullable JSON field will likely be added to the Device and VirtualMachine models to store the pre-rendered config context data. ### External dependencies N/A
adam added the type: featurenetboxneeds milestonestatus: backlogcomplexity: high labels 2025-12-29 21:51:47 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11946