: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
fix(tasks): index webhook task run lookups (#87779)
Sven Lange3f79e1fe142a
diff --git a/products/tasks/backend/migrations/0105_taskrun_webhook_lookup_indexes.py b/products/tasks/backend/migrations/0105_taskrun_webhook_lookup_indexes.pynew file mode 100644index 000000000000..c9fd54c0ee5b--- /dev/null+++ b/products/tasks/backend/migrations/0105_taskrun_webhook_lookup_indexes.py@@ -0,0 +1,39 @@+from django.contrib.postgres.indexes import GinIndex, OpClass+from django.db import migrations, models+from django.db.models.fields.json import KeyTransform++from posthog.migration_helpers import SafeAddIndexConcurrently+++class Migration(migrations.Migration):+ atomic = False++ dependencies = [+ ("posthog", "1315_githubinstallrequest_account"),+ ("tasks", "0104_desktop_beta_terms_acceptance"),+ ]++ operations = [+ SafeAddIndexConcurrently(+ model_name="taskrun",+ index=GinIndex(+ OpClass(KeyTransform("verified_pr_urls", "state"), name="jsonb_path_ops"),+ name="task_run_verified_pr_urls_idx",+ ),+ ),+ SafeAddIndexConcurrently(+ model_name="taskrun",+ index=GinIndex(+ OpClass(KeyTransform("head_branches", "output"), name="jsonb_path_ops"),+ name="task_run_head_branches_idx",+ ),+ ),+ SafeAddIndexConcurrently(+ model_name="taskrun",+ index=models.Index(+ fields=["branch"],+ name="task_run_branch_idx",+ condition=models.Q(branch__isnull=False),+ ),+ ),+ ]diff --git a/products/tasks/backend/migrations/max_migration.txt b/products/tasks/backend/migrations/max_migration.txtindex ff8c6609af0f..25bea1ad8b2a 100644--- a/products/tasks/backend/migrations/max_migration.txt+++ b/products/tasks/backend/migrations/max_migration.txt@@ -1 +1 @@-0104_desktop_beta_terms_acceptance+0105_taskrun_webhook_lookup_indexesdiff --git a/products/tasks/backend/models.py b/products/tasks/backend/models.pyindex 0b170b236603..28b43672881f 100644--- a/products/tasks/backend/models.py+++ b/products/tasks/backend/models.py@@ -20,7 +20,7 @@ if TYPE_CHECKING:from django.conf import settingsfrom django.contrib.postgres.fields import ArrayField-from django.contrib.postgres.indexes import GinIndex+from django.contrib.postgres.indexes import GinIndex, OpClassfrom django.core.exceptions import ValidationErrorfrom django.db import IntegrityError, connection, models, transactionfrom django.db.models.fields.json import KeyTransform@@ -1987,6 +1987,19 @@ class TaskRun(models.Model):db_table = "posthog_task_run"ordering = ["-created_at"]indexes = [+ GinIndex(+ OpClass(KeyTransform("verified_pr_urls", "state"), name="jsonb_path_ops"),+ name="task_run_verified_pr_urls_idx",+ ),+ GinIndex(+ OpClass(KeyTransform("head_branches", "output"), name="jsonb_path_ops"),+ name="task_run_head_branches_idx",+ ),+ models.Index(+ fields=["branch"],+ name="task_run_branch_idx",+ condition=models.Q(branch__isnull=False),+ ),# Partial functional index backing the per-PR-webhook lookup# `filter(output__pr_url=...)`. The equality lookup implies the key is# present, so the `IS NOT NULL` condition keeps the index off the many