: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(signals): index scout runs by team and newest first (#111681)
posthog[bot]f9bcb2727a7e
diff --git a/products/signals/backend/migrations/0167_signalscoutrun_team_new_idx.py b/products/signals/backend/migrations/0167_signalscoutrun_team_new_idx.pynew file mode 100644index 000000000000..0353091d2032--- /dev/null+++ b/products/signals/backend/migrations/0167_signalscoutrun_team_new_idx.py@@ -0,0 +1,16 @@+from django.db import migrations, models++from posthog.migration_helpers import SafeAddIndexConcurrently+++class Migration(migrations.Migration):+ atomic = False++ dependencies = [("signals", "0166_signalscratchpad_indexes")]++ operations = [+ SafeAddIndexConcurrently(+ model_name="signalscoutrun",+ index=models.Index(fields=["team", "-created_at"], name="signal_scout_run_team_new_idx"),+ ),+ ]diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txtindex 164746f9f297..99db99139fef 100644--- a/products/signals/backend/migrations/max_migration.txt+++ b/products/signals/backend/migrations/max_migration.txt@@ -1 +1 @@-0166_signalscratchpad_indexes+0167_signalscoutrun_team_new_idxdiff --git a/products/signals/backend/models.py b/products/signals/backend/models.pyindex 50c403e4330d..b1fa6faa7dfc 100644--- a/products/signals/backend/models.py+++ b/products/signals/backend/models.py@@ -3111,6 +3111,10 @@ class SignalScoutRun(TeamScopedRootMixin, UUIDModel):fields=["team", "skill_name", "-created_at"],name="signal_scout_run_recent_idx",),+ # The team-wide run search and the fleet summary filter on team only, with no scout key, so+ # the index above cannot serve their newest-first order and the planner sorts every one of+ # the team's runs before it applies the limit.+ models.Index(fields=["team", "-created_at"], name="signal_scout_run_team_new_idx"),# "which run authored this report?" is a jsonb containment lookup (`@>`) that# `dismissal_notes` runs on the dismissal request path, batched into one OR'd query per# request. Without these the planner can only seq-scan the team's runs, and this table