Cache the assigned site, location, and rack of device components #11425

Closed
opened 2025-12-29 21:45:06 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Jul 29, 2025).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.3.5

Feature type

New functionality

Proposed functionality

For all device components, cache the assigned site and location of the parent device. This assignment will be read-only, and updated automatically whenever the device's assignment is altered.

There is an existing pattern for how this can be handled using a receiver for the post_save signal.

Use case

Saving these assignments directly on each component will obviate the need for SQL table joins when filtering device components by parent site or location. For example, consider the following REST API query:

GET /api/dcim/interfaces/?site_id=123

This currently requires a JOIN of the dcim_interface table with the dcim_device table to query the site. Copying this relationship to the dcim_interface table allows the filter to query that table directly.

Database changes

No response

External dependencies

No response

Originally created by @jeremystretch on GitHub (Jul 29, 2025). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.3.5 ### Feature type New functionality ### Proposed functionality For all device components, cache the assigned site and location of the parent device. This assignment will be read-only, and updated automatically whenever the device's assignment is altered. There is an [existing pattern](https://github.com/netbox-community/netbox/blob/6ca390871525c248b56f9e941bc4f1fa28b86a69/netbox/dcim/signals.py#L19) for how this can be handled using a receiver for the `post_save` signal. ### Use case Saving these assignments directly on each component will obviate the need for SQL table joins when filtering device components by parent site or location. For example, consider the following REST API query: ``` GET /api/dcim/interfaces/?site_id=123 ``` This currently requires a `JOIN` of the `dcim_interface` table with the `dcim_device` table to query the site. Copying this relationship to the `dcim_interface` table allows the filter to query that table directly. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: featurecomplexity: medium labels 2025-12-29 21:45:06 +01:00
adam closed this issue 2025-12-29 21:45:06 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11425