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(replay-vision): index observations by team and session (#101314)

Tue Haulund216aadb69896
diff --git a/products/replay_vision/backend/migrations/0095_replayobservation_rlo_team_session_idx.py b/products/replay_vision/backend/migrations/0095_replayobservation_rlo_team_session_idx.py
new file mode 100644
index 000000000000..4edb469377c5
--- /dev/null
+++ b/products/replay_vision/backend/migrations/0095_replayobservation_rlo_team_session_idx.py
@@ -0,0 +1,19 @@
+from django.db import migrations, models
+
+from posthog.migration_helpers import SafeAddIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ # CREATE INDEX CONCURRENTLY cannot run inside a transaction.
+ atomic = False
+
+ dependencies = [
+ ("replay_vision", "0094_alter_replayobservationusage_organization"),
+ ]
+
+ operations = [
+ SafeAddIndexConcurrently(
+ model_name="replayobservation",
+ index=models.Index(fields=["team", "session_id"], name="rlo_team_session_idx"),
+ ),
+ ]
diff --git a/products/replay_vision/backend/migrations/max_migration.txt b/products/replay_vision/backend/migrations/max_migration.txt
index 9f2eef06bebe..278010bce5f8 100644
--- a/products/replay_vision/backend/migrations/max_migration.txt
+++ b/products/replay_vision/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0094_alter_replayobservationusage_organization
+0095_replayobservation_rlo_team_session_idx
diff --git a/products/replay_vision/backend/models/replay_observation.py b/products/replay_vision/backend/models/replay_observation.py
index d0846aa83058..7a7335763af6 100644
--- a/products/replay_vision/backend/models/replay_observation.py
+++ b/products/replay_vision/backend/models/replay_observation.py
@@ -131,6 +131,8 @@ class ReplayObservation(UUIDModel):
]
indexes = [
models.Index(fields=["team", "created_at"], name="rlo_team_created_idx"),
+ # Serves the recording-delete cleanup, which looks rows up by session rather than scanner.
+ models.Index(fields=["team", "session_id"], name="rlo_team_session_idx"),
models.Index(fields=["scanner", "status"], name="rlo_scanner_status_idx"),
# Serves the alert-engine observation window: succeeded rows per scanner in a
# completed_at range. Partial: terminal succeeded rows are the only ones scanned.