Closes #21420: Improve query performance of ContentTypeFilter #343

Closed
opened 2026-04-05 16:26:42 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 2/16/2026

Fixes: #21420

This change improves the performance of ContentTypeFilter by resolving the ContentType up front using ContentType.objects.get_by_natural_key(<app_label>, <model>) and then filtering directly on the FK value. This avoids an unnecessary INNER JOIN to django_content_type that occurs when filtering via __app_label/__model.

Behavior remains the same for valid values, and invalid or unknown content types still return qs.none().

Thanks for taking the time to review this PR!

*Originally created by @pheus on 2/16/2026* ### Fixes: #21420 This change improves the performance of `ContentTypeFilter` by resolving the `ContentType` up front using `ContentType.objects.get_by_natural_key(<app_label>, <model>)` and then filtering directly on the FK value. This avoids an unnecessary `INNER JOIN` to `django_content_type` that occurs when filtering via `__app_label`/`__model`. Behavior remains the same for valid values, and invalid or unknown content types still return `qs.none()`. Thanks for taking the time to review this PR!
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#343