[PR #18801] [CLOSED] Fixes: #18606 UI Racks Table View Performance Scaling Problem - Loading time increases with large number of racks - django N+1 query issue #15440

Closed
opened 2025-12-30 00:21:55 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18801
Author: @renatoalmeidaoliveira
Created: 3/4/2025
Status: Closed

Base: mainHead: 18606-n+1-rack-table-view


📝 Commits (1)

  • 0e41973 Add reservations prefetch to RackListView queryset

📊 Changes

1 file changed (+5 additions, -2 deletions)

View changed files

📝 netbox/dcim/views.py (+5 -2)

📄 Description

Fixes: #18606 UI Racks Table View Performance Scaling Problem - Loading time increases with large number of racks - django N+1 query issue

  • The issue happens with the collumns: get_utilization and get_power_utilization
  • Both collumns are calculated inside the model
  • Adding a prefetch for reservations inside the RackListView queryset partially fixes the problem reduncing the amount of queries from 123 to 85 using NetBox sample data with 42 rack models

Investigating the get_utilization method of the Rack model and comparing with the executed queries in the List view it seens the N+1 queries happens from this line


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/18801 **Author:** [@renatoalmeidaoliveira](https://github.com/renatoalmeidaoliveira) **Created:** 3/4/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `18606-n+1-rack-table-view` --- ### 📝 Commits (1) - [`0e41973`](https://github.com/netbox-community/netbox/commit/0e419738c8f3789fcb9490dc7e01725dc7e965b6) Add reservations prefetch to RackListView queryset ### 📊 Changes **1 file changed** (+5 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/views.py` (+5 -2) </details> ### 📄 Description ### Fixes: #18606 UI Racks Table View Performance Scaling Problem - Loading time increases with large number of racks - django N+1 query issue - The issue happens with the collumns: `get_utilization` and `get_power_utilization` - Both collumns are calculated inside the model - Adding a prefetch for `reservations` inside the `RackListView` queryset partially fixes the problem reduncing the amount of queries from 123 to 85 using NetBox sample data with 42 rack models Investigating the `get_utilization` method of the `Rack` model and comparing with the executed queries in the List view it seens the N+1 queries happens from this [line](https://github.com/netbox-community/netbox/blob/d208ddde9af2859299b9923b05872c91d307c046/netbox/dcim/models/racks.py#L517) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:21:55 +01:00
adam closed this issue 2025-12-30 00:21:56 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15440