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.

feat(warehouse_sources): add pipeline/status/finished_at index on external data jobs (#90829)

José Sequeira2cdfeb8573dd
diff --git a/products/warehouse_sources/backend/migrations/0156_externaldatajob_pipeline_status_finished_idx.py b/products/warehouse_sources/backend/migrations/0156_externaldatajob_pipeline_status_finished_idx.py
new file mode 100644
index 000000000000..064834d7538a
--- /dev/null
+++ b/products/warehouse_sources/backend/migrations/0156_externaldatajob_pipeline_status_finished_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", "0155_repin_github_api_version")]
+
+ operations = [
+ SafeAddIndexConcurrently(
+ model_name="externaldatajob",
+ index=models.Index(
+ fields=["pipeline", "status", "finished_at"],
+ name="idx_extdatajob_pipe_stat_fin",
+ ),
+ ),
+ ]
diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txt
index df8b62e1ba7f..857ff21228bf 100644
--- a/products/warehouse_sources/backend/migrations/max_migration.txt
+++ b/products/warehouse_sources/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0155_repin_github_api_version
+0156_externaldatajob_pipeline_status_finished_idx
diff --git a/products/warehouse_sources/backend/models/external_data_job.py b/products/warehouse_sources/backend/models/external_data_job.py
index d7cb03920289..e9d8ae02feb1 100644
--- a/products/warehouse_sources/backend/models/external_data_job.py
+++ b/products/warehouse_sources/backend/models/external_data_job.py
@@ -55,6 +55,13 @@ class ExternalDataJob(CreatedMetaFields, UpdatedMetaFields, UUIDTModel):
fields=["updated_at"],
name="idx_extdatajob_updated_at",
),
+ # Serves the rows-synced aggregates (usage report, source health): equality on
+ # pipeline/status with a finished_at range. Without it the FK index walks every
+ # job for the pipeline and filters most of them out.
+ models.Index(
+ fields=["pipeline", "status", "finished_at"],
+ name="idx_extdatajob_pipe_stat_fin",
+ ),
]
def folder_path(self) -> str: