mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-19 15:27:44 +01:00
perf(filters): Avoid ContentType join in ContentTypeFilter
Resolve the ContentType via get_by_natural_key() and filter by the FK value to prevent an unnecessary join to django_content_type. Fixes #21420
This commit is contained in:
committed by
Jeremy Stretch
parent
862593f2dd
commit
f4c3c90bab
@@ -165,12 +165,12 @@ class ContentTypeFilter(django_filters.CharFilter):
|
||||
|
||||
try:
|
||||
app_label, model = value.lower().split('.')
|
||||
except ValueError:
|
||||
content_type = ContentType.objects.get_by_natural_key(app_label, model)
|
||||
except (ValueError, ContentType.DoesNotExist):
|
||||
return qs.none()
|
||||
return qs.filter(
|
||||
**{
|
||||
f'{self.field_name}__app_label': app_label,
|
||||
f'{self.field_name}__model': model
|
||||
f'{self.field_name}': content_type,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user