Skip to content

: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.

fix(data-warehouse): shrink new-source wizard payload and gzip it (#70804)

Daniel RC5686468e8e3a
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 456513dd9eed..6e6152944b46 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -840,6 +840,9 @@ GZIP_RESPONSE_ALLOW_LIST = get_list(
"^/api/organizations/@current/plugins/?$",
"^api/(environments|projects)/@current/feature_flags/my_flags/?$",
"^/?api/(environments|projects)/\\d+/query/?$",
+ # Deploy-static source catalog (no user input or secrets reflected): several
+ # hundred KB of JSON that compresses ~7x.
+ "^/?api/(environments|projects)/(\\d+|@current)/external_data_sources/wizard/?$",
"^/?api/instance_status/?$",
"^/array/.*$",
]
diff --git a/products/data_warehouse/backend/presentation/views/external_data_source.py b/products/data_warehouse/backend/presentation/views/external_data_source.py
index 680fdb3da997..3cf597f02d75 100644
--- a/products/data_warehouse/backend/presentation/views/external_data_source.py
+++ b/products/data_warehouse/backend/presentation/views/external_data_source.py
@@ -4161,7 +4161,9 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
)
@action(methods=["GET"], detail=False)
def wizard(self, request: Request, *arg: Any, **kwargs: Any):
- configs = build_source_configs()
+ # The documented-tables catalog is only consumed by the posthog.com docs build (via the
+ # public endpoint) — skipping it here cuts ~40% off an already >1 MB response.
+ configs = build_source_configs(include_tables=False)
requested = request.query_params.get("source_type")
if requested:
diff --git a/products/data_warehouse/backend/presentation/views/public_source_configs.py b/products/data_warehouse/backend/presentation/views/public_source_configs.py
index c6abc74cec6e..f2844cda2a5d 100644
--- a/products/data_warehouse/backend/presentation/views/public_source_configs.py
+++ b/products/data_warehouse/backend/presentation/views/public_source_configs.py
@@ -1,3 +1,5 @@
+import functools
+
import structlog
from drf_spectacular.utils import extend_schema
from rest_framework import permissions, status, viewsets
@@ -11,12 +13,18 @@ from products.warehouse_sources.backend.facade.source_management import SourceRe
logger = structlog.get_logger(__name__)
-def build_source_configs() -> dict[str, dict]:
+def build_source_configs(*, include_tables: bool = True) -> dict[str, dict]:
"""Build the source-config catalog returned by both the public endpoint and the wizard.
- Each entry is the source's ``SourceConfig`` augmented with ``supportsColumnSelection`` and a
- credential-free ``tables`` catalog (empty for SQL/file sources with user-defined schemas). Kept
- in one place so the two endpoints can never drift (see ``test_matches_wizard_response``).
+ Each entry is the source's ``SourceConfig`` augmented with ``supportsColumnSelection`` and,
+ when ``include_tables`` is set, a credential-free ``tables`` catalog (empty for SQL/file
+ sources with user-defined schemas). ``tables`` exists for the posthog.com docs build; the
+ in-app wizard skips it because nothing in the app reads it and it is ~40% of the payload.
+ Kept in one place so the two endpoints can never drift (see ``test_matches_wizard_response``).
+
+ The catalog is deploy-static (it only changes when source code ships), so the result is
+ memoized per process — callers must treat it as read-only.
"""
sources = SourceRegistry.get_all_sources()
@@ -24,12 +32,13 @@ def build_source_configs() -> dict[str, dict]:
for source_type, source in sources.items():
config = source.get_source_config.model_dump()
config["supportsColumnSelection"] = bool(source.supports_column_selection)
- # Per-source guard: a single misbehaving source must never break the whole catalog.
- try:
- config["tables"] = source.get_documented_tables()
- except Exception:
- logger.exception("build_source_configs: get_documented_tables failed", source_type=str(source_type))
- config["tables"] = []
+ if include_tables:
+ # Per-source guard: a single misbehaving source must never break the whole catalog.
+ try:
+ config["tables"] = source.get_documented_tables()
+ except Exception:
+ logger.exception("build_source_configs: get_documented_tables failed", source_type=str(source_type))
+ config["tables"] = []
results[str(source_type)] = config
return results
diff --git a/products/data_warehouse/backend/tests/api/test_public_source_configs.py b/products/data_warehouse/backend/tests/api/test_public_source_configs.py
index 6571077b7d2e..bdb0cafc48e4 100644
--- a/products/data_warehouse/backend/tests/api/test_public_source_configs.py
+++ b/products/data_warehouse/backend/tests/api/test_public_source_configs.py
@@ -19,14 +19,22 @@ class TestPublicSourceConfigs(APIBaseTest):
assert "fields" in first_config
def test_matches_wizard_response(self):
- """Public endpoint should return the same data as the authenticated /wizard endpoint."""
+ """Public endpoint returns the same data as the authenticated /wizard endpoint, plus the
+ docs-only `tables` catalog the wizard deliberately omits to keep its payload small."""
response = self.client.get("/api/public_source_configs/")
assert response.status_code == status.HTTP_200_OK
wizard_response = self.client.get("/api/environments/@current/external_data_sources/wizard/")
assert wizard_response.status_code == status.HTTP_200_OK
- assert response.json() == wizard_response.json()
+ wizard_data = wizard_response.json()
+ assert not any("tables" in config for config in wizard_data.values())
+
+ public_without_tables = {
+ source_type: {k: v for k, v in config.items() if k != "tables"}
+ for source_type, config in response.json().items()
+ }
+ assert public_without_tables == wizard_data
def test_accessible_without_authentication(self):
self.client.logout()