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.

perf(warehouse-sources): index the source job history read (#92370)

posthog[bot]67d541cf309d
diff --git a/products/warehouse_sources/backend/migrations/0171_externaldatajob_pipeline_created_idx.py b/products/warehouse_sources/backend/migrations/0171_externaldatajob_pipeline_created_idx.py
new file mode 100644
index 000000000000..160c9c8e78ed
--- /dev/null
+++ b/products/warehouse_sources/backend/migrations/0171_externaldatajob_pipeline_created_idx.py
@@ -0,0 +1,19 @@
+from django.db import migrations, models
+
+from posthog.migration_helpers import SafeAddIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ # Concurrent index builds cannot run inside a transaction.
+ atomic = False
+ dependencies = [("warehouse_sources", "0170_externaldataschema_full_refresh_time_of_day")]
+
+ operations = [
+ SafeAddIndexConcurrently(
+ model_name="externaldatajob",
+ index=models.Index(
+ fields=["pipeline", "-created_at"],
+ name="idx_extdatajob_pipe_created",
+ ),
+ ),
+ ]
diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txt
index ba7ac3944777..7dfba46caede 100644
--- a/products/warehouse_sources/backend/migrations/max_migration.txt
+++ b/products/warehouse_sources/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0170_externaldataschema_full_refresh_time_of_day
+0171_externaldatajob_pipeline_created_idx
diff --git a/products/warehouse_sources/backend/models/external_data_job.py b/products/warehouse_sources/backend/models/external_data_job.py
index c42b2bf7d59b..f151d0ee967f 100644
--- a/products/warehouse_sources/backend/models/external_data_job.py
+++ b/products/warehouse_sources/backend/models/external_data_job.py
@@ -91,6 +91,13 @@ class ExternalDataJob(CreatedMetaFields, UpdatedMetaFields, UUIDTModel):
condition=Q(status=ExternalDataJobStatus.RUNNING),
name="idx_extdatajob_running",
),
+ # Serves the source sync-history list (the `jobs` action): equality on pipeline
+ # ordered by created_at DESC with LIMIT. The polling settings tab reads it every
+ # few seconds. Without it the FK index walks every job of the source and sorts.
+ models.Index(
+ fields=["pipeline", "-created_at"],
+ name="idx_extdatajob_pipe_created",
+ ),
]
def folder_path(self) -> str: