Explorar el Código

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
Martin Hauser hace 16 horas
padre
commit
f4c3c90bab
Se han modificado 1 ficheros con 3 adiciones y 3 borrados
  1. 3 3
      netbox/utilities/filters.py

+ 3 - 3
netbox/utilities/filters.py

@@ -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}__model': model
+                f'{self.field_name}': content_type,
             }
             }
         )
         )