Disable natural ordering of interfaces when no device is specified #2610

Closed
opened 2025-12-29 18:20:22 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (May 10, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.12

Proposed Functionality

Disable natural ordering of interfaces (and possibly other device components) in the API when the query has not been filtered to a specific device. I haven't dug too much into this yet, but it will likely involve overriding get_queryset() on the relevant API endpoints to check for a device filter in the request.

Use Case

Currently, the interfaces list is always ordered naturally using an array of regular expressions at query time. This introduces a substantial amount of overhead and delay when dealing with large numbers (hundreds of thousands) of objects.

#3097 has been opened to replace the regex-on-query approach with a set of discrete fields which can be indexed to support much faster queries. This proposal is a stop-gap solution to ease performance pains until the new approach can be implemented.

Database Changes

None

External Dependencies

None

Originally created by @jeremystretch on GitHub (May 10, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.5.12 ### Proposed Functionality Disable natural ordering of interfaces (and possibly other device components) in the API when the query has not been filtered to a specific device. I haven't dug too much into this yet, but it will likely involve overriding `get_queryset()` on the relevant API endpoints to check for a device filter in the request. ### Use Case Currently, the interfaces list is always ordered naturally using an array of regular expressions at query time. This introduces a substantial amount of overhead and delay when dealing with large numbers (hundreds of thousands) of objects. #3097 has been opened to replace the regex-on-query approach with a set of discrete fields which can be indexed to support much faster queries. This proposal is a stop-gap solution to ease performance pains until the new approach can be implemented. ### Database Changes None ### External Dependencies None
adam closed this issue 2025-12-29 18:20:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 29, 2019):

I took a shot at this, but moving the naturally ordering logic out of the default manager and into a queryset method means we need to invoke that method everywhere interfaces need to be ordered naturally. We'd inevitably end up chasing down calls that get missed, now and in the future.

I also tried adding a second manager specifically to handle unordered queries, but that means repeating the entire queryset definition for each manager, which can get really dirty.

We're probably best off just tolerating the performance hit for now and focusing on #3097.

@jeremystretch commented on GitHub (May 29, 2019): I took a shot at this, but moving the naturally ordering logic out of the default manager and into a queryset method means we need to invoke that method _everywhere_ interfaces need to be ordered naturally. We'd inevitably end up chasing down calls that get missed, now and in the future. I also tried adding a second manager specifically to handle unordered queries, but that means repeating the entire queryset definition for each manager, which can get really dirty. We're probably best off just tolerating the performance hit for now and focusing on #3097.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2610