:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(data-modeling): stop loading nodes per edge in the edges list (#111265)
Jovan Sakovic6f32861014f6
diff --git a/products/data_modeling/backend/presentation/views/edge.py b/products/data_modeling/backend/presentation/views/edge.pyindex dc844a248c1e..b9491db110bf 100644--- a/products/data_modeling/backend/presentation/views/edge.py+++ b/products/data_modeling/backend/presentation/views/edge.py@@ -19,8 +19,8 @@ def _connects_a_metric(edge: Edge) -> bool:class EdgeSerializer(serializers.ModelSerializer):- source_id = serializers.UUIDField(source="source.id", read_only=True)- target_id = serializers.UUIDField(source="target.id", read_only=True)+ source_id = serializers.UUIDField(read_only=True, help_text="ID of the upstream node.")+ target_id = serializers.UUIDField(read_only=True, help_text="ID of the downstream node.")dag_name = serializers.SerializerMethodField(read_only=True)class Meta:diff --git a/products/data_modeling/backend/tests/api/test_node_api.py b/products/data_modeling/backend/tests/api/test_node_api.pyindex cb8222d47d21..781ab75646c8 100644--- a/products/data_modeling/backend/tests/api/test_node_api.py+++ b/products/data_modeling/backend/tests/api/test_node_api.py@@ -5,6 +5,8 @@ import pytestfrom posthog.test.base import APIBaseTestfrom unittest.mock import AsyncMock, patch+from django.db import connection+from django.test.utils import CaptureQueriesContextfrom django.utils import timezonefrom parameterized import parameterized@@ -1074,6 +1076,22 @@ class TestEdgeViewSet(APIBaseTest):self.assertEqual(edge["target_id"], str(self.target_node.id))self.assertEqual(edge["dag"], str(self.dag.id))+ def test_list_edges_query_count_does_not_grow_with_edges(self):+ url = f"/api/environments/{self.team.id}/data_modeling_edges/"+ self.client.get(url)+ with CaptureQueriesContext(connection) as baseline:+ self.client.get(url)++ for i in range(5):+ target = Node.objects.create(team=self.team, dag=self.dag, name=f"table_{i}", type=NodeType.TABLE)+ Edge.objects.create(team=self.team, dag=self.dag, source=self.source_node, target=target)++ with CaptureQueriesContext(connection) as grown:+ response = self.client.get(url)++ self.assertEqual(response.json()["count"], 6)+ self.assertEqual(len(grown.captured_queries), len(baseline.captured_queries))+def test_list_edges_with_dag_filter(self):another_dag = DAG.objects.create(team=self.team, name="another_dag")another_source = Node.objects.create(diff --git a/products/data_modeling/frontend/generated/api.schemas.ts b/products/data_modeling/frontend/generated/api.schemas.tsindex 899447f92047..0eca7b345fcd 100644--- a/products/data_modeling/frontend/generated/api.schemas.ts+++ b/products/data_modeling/frontend/generated/api.schemas.ts@@ -58,7 +58,9 @@ export interface PatchedDAGApi {export interface EdgeApi {readonly id: string+ /** ID of the upstream node. */readonly source_id: string+ /** ID of the downstream node. */readonly target_id: stringdag: stringreadonly dag_name: string@@ -79,7 +81,9 @@ export interface PaginatedEdgeListApi {export interface PatchedEdgeApi {readonly id?: string+ /** ID of the upstream node. */readonly source_id?: string+ /** ID of the downstream node. */readonly target_id?: stringdag?: stringreadonly dag_name?: stringdiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 12bba1677738..3afccc7af4cd 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -36713,7 +36713,9 @@ export namespace Schemas {export interface Edge {readonly id: string;+ /** ID of the upstream node. */readonly source_id: string;+ /** ID of the downstream node. */readonly target_id: string;dag: string;readonly dag_name: string;@@ -75642,7 +75644,9 @@ export namespace Schemas {export interface PatchedEdge {readonly id?: string;+ /** ID of the upstream node. */readonly source_id?: string;+ /** ID of the downstream node. */readonly target_id?: string;dag?: string;readonly dag_name?: string;