Cache the number of each component type assigned to devices/VMs #4872

Closed
opened 2025-12-29 19:21:26 +01:00 by adam · 3 comments
Owner

Originally created by @jeremystretch on GitHub (May 4, 2021).

Originally assigned to: @arthanson on GitHub.

Proposed Changes

Add the following integer fields to dcim.Device:

  • _console_port_count
  • _console_server_port_count
  • _power_port_count
  • _power_outlet_count
  • _interface_count
  • _front_port_count
  • _rear_port_count
  • _device_bay_count
  • _inventory_item_count

Add the following integer fields to virtualization.VirtualMachine:

  • _interface_count

These fields would be automatically populated upon creating/modifying/deleting the relevant child components.

Justification

  • Enables efficient filters of devices/VMs based on whether a certain type of component has been created.
  • Eliminates the need for additional queries e.g. when display the device view.
Originally created by @jeremystretch on GitHub (May 4, 2021). Originally assigned to: @arthanson on GitHub. ### Proposed Changes Add the following integer fields to dcim.Device: * `_console_port_count` * `_console_server_port_count` * `_power_port_count` * `_power_outlet_count` * `_interface_count` * `_front_port_count` * `_rear_port_count` * `_device_bay_count` * `_inventory_item_count` Add the following integer fields to virtualization.VirtualMachine: * `_interface_count` These fields would be automatically populated upon creating/modifying/deleting the relevant child components. ### Justification * Enables efficient filters of devices/VMs based on whether a certain type of component has been created. * Eliminates the need for additional queries e.g. when display the device view.
adam added the status: acceptedtype: feature labels 2025-12-29 19:21:26 +01:00
adam closed this issue 2025-12-29 19:21:27 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 11, 2021):

This might also be a use case for CTE; see #6587.

@jeremystretch commented on GitHub (Jun 11, 2021): This might also be a use case for CTE; see #6587.
Author
Owner

@AndMrzv commented on GitHub (Apr 7, 2022):

I also like to verify that devices match their device type templates (you know something's up if a 24port 1PSU switch suddenly has 29 interfaces and 3 power ports). So maybe you'll find it useful to add same data to device types, maybe expand the idea to strict matching devices to their types or syncing (now I do this with API and Bash).

@AndMrzv commented on GitHub (Apr 7, 2022): I also like to verify that devices match their device type templates (you know something's up if a 24port 1PSU switch suddenly has 29 interfaces and 3 power ports). So maybe you'll find it useful to add same data to device types, maybe expand the idea to strict matching devices to their types or syncing (now I do this with API and Bash).
Author
Owner

@ryanmerolle commented on GitHub (Mar 23, 2023):

pushed to 3.6 milestone

@ryanmerolle commented on GitHub (Mar 23, 2023): pushed to 3.6 milestone
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4872