-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Description
NetBox Edition
NetBox Community
NetBox Version
v4.4.4
Python Version
3.12
Steps to Reproduce
- Have thousands of devices, each with ~100 or more inventory items installed.
- Attempt to search for a device by name using the
qfilter, e.g.
GET /api/dcim/devices/?brief=true&limit=100&q=foobar
Expected Behavior
The set of matching devices should be returned fairly quickly.
Observed Behavior
The query takes an inordinate amount of time due to the underlying search() method pulling in all installed inventory items:
return queryset.filter(
Q(name__icontains=value) |
Q(virtual_chassis__name__icontains=value) |
Q(serial__icontains=value.strip()) |
Q(inventoryitems__serial__icontains=value.strip()) | # Queries *all* inventory items
Q(asset_tag__icontains=value.strip()) |
Q(description__icontains=value.strip()) |
Q(comments__icontains=value) |
Q(primary_ip4__address__startswith=value) |
Q(primary_ip6__address__startswith=value)
).distinct()While I can appreciate the utility in including these, it has a very pronounced impact on performance when many inventory items have been created. I propose removing the inventoryitems__serial__icontains lookup from the search() method, and perhaps introducing a more narrowly-focused filter to search specifically on serial number and/or asset tag of the device and its inventory items.
Metadata
Metadata
Assignees
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application