Custom field accessor database performance #3185
Labels
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
Environment
Use Case
One of the Netbox reports that we've written, needs to basically look at multiple Devices, and for each of them check various fields against another database for consistency. Some of them are Netbox's built-in fields, some of them are custom fields. Basically, semi-realistic example:
Observed behavior
Netbox issues hundreds of database queries, making this inefficient, slow and tough on the database. The
.cf()
accessor seems to be the culprit, as it's making a lot of queries for each of the ContentTypes etc., for each of those Device objects.Proposed behavior
We've worked around that, with this piece of code:
This reduces the hotpath queries to just 1 big one, making this code path about 20-30x more efficient.
I think this could be generalized, and potentially replace the
.cf()
accessor.I'm unaware of the history of
.cf()
, and it is a complicated piece of code, so I'm a bit hesitant diving in and submitting a PR there. Would love some guidance :)The text was updated successfully, but these errors were encountered: