diff --git a/cdip_admin/integrations/admin.py b/cdip_admin/integrations/admin.py index 2b8e57e08..d1362186d 100644 --- a/cdip_admin/integrations/admin.py +++ b/cdip_admin/integrations/admin.py @@ -436,10 +436,15 @@ class WebhookConfigurationAdmin(admin.ModelAdmin): class RouteProviderInline(admin.TabularInline): model = Route.data_providers.through + # Without this, every inline row renders a of *every* + Integration, and Integration.__str__ touches owner.name and type.name + (neither select_related), so building the dropdowns is an N+1 storm whose + cost grows with the number of integrations -- the cause of the timeout. + The query count must stay flat as integrations are added. + """ + url = reverse("admin:integrations_route_change", args=[route_1.pk]) + + baseline = _render_query_count(admin_client, url) + + # bulk_create bypasses save hooks/dispatcher deployment -- we only need + # rows that would populate the inline FK dropdowns. + Integration.objects.bulk_create( + [ + Integration( + type=integration_type_er, + owner=organization, + name=f"Bulk Integration {i}", + base_url=f"https://bulk-{i}.example.org", + ) + for i in range(100) + ] + ) + + after = _render_query_count(admin_client, url) + + assert after - baseline <= 10, ( + "Route change page query count scales with integration count: " + f"{baseline} queries -> {after} queries after adding 100 integrations. " + "Inline FK fields should use autocomplete_fields." + )