-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v3.4.2
Feature type
New functionality
Proposed functionality
Add new filters to NetBoxModelFilterSet which enable a user to filter for objects based on the ID and action of an associated change record. For example, suppose you want to find all sites that were created as the result of a specific request. This proposal would enable you to filter send a request such as:
GET /dcim/sites/?objectchange_request_id=e39c84bc-f169-4d5f-bc1c-94487a1b18b5
This filter would perform two lookups:
- Find all ObjectChanges with the specified request ID pertaining to site objects, and return a list containing the ID of each site.
- Return a queryset containing all sites matched by the list of IDs.
Although we're making two queries, overhead shouldn't be too bad as the first is returning only the related object IDs. However we probably want to add a database index for the request_id column.
(I'm open to suggestions regarding the specific filter name. I'd like to avoid using the term "change request" as that could be very confusing to the user.)
Use case
The initial catalyst for this idea came from #10242, which seeks to optimize our approach for returning newly-imported objects. However, this functionality will likely find many additional use cases.
Shout-out to @DanSheps who first proposed this strategy.
Database changes
Add an index for extras_objectchange.request_id to optimize queries. This can be accomplished using a simple migration.
External dependencies
No response