mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-19 15:31:35 +02: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:
|
try:
|
||||||
app_label, model = value.lower().split('.')
|
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.none()
|
||||||
return qs.filter(
|
return qs.filter(
|
||||||
**{
|
**{
|
||||||
f'{self.field_name}__app_label': app_label,
|
f'{self.field_name}': content_type,
|
||||||
f'{self.field_name}__model': model
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user