: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(replay-vision): count highlight group reach from member rows (#125500)
Tue Haulund0ad9cb2d3bec
diff --git a/products/replay_vision/backend/tests/test_api.py b/products/replay_vision/backend/tests/test_api.pyindex 4b2927a22720..80c301b40f7d 100644--- a/products/replay_vision/backend/tests/test_api.py+++ b/products/replay_vision/backend/tests/test_api.py@@ -4957,8 +4957,11 @@ class TestHighlightFeedAPI(_VisionAPITestCase):self._ranked_observation(scanner, "copy", 400, "failure", -0.5, group=str(oldest.id))for index in range(10):self._ranked_observation(scanner, f"routine-{index}", index)+ # A row outside the reader's scanner selection never counts, even under the same group id.+ other = self._create_scanner(name="other")+ self._ranked_observation(other, "elsewhere", 300, "failure", 0.9, group=str(oldest.id))- items = self.client.get(self.feed_url).json()["results"]+ items = self.client.get(self.feed_url, {"scanner_ids": str(scanner.id)}).json()["results"]picks = [item for item in items if item["reason"]["kind"] == "embedding_pick"]self.assertEqual([item["observation"]["session_id"] for item in picks], ["oldest-failure"])self.assertEqual(picks[0]["reason"]["similar_count"], 1)diff --git a/products/replay_vision/backend/watch_rank.py b/products/replay_vision/backend/watch_rank.pyindex 9e8abdce741c..cb2b5df02879 100644--- a/products/replay_vision/backend/watch_rank.py+++ b/products/replay_vision/backend/watch_rank.py@@ -396,16 +396,25 @@ def select_embedding_picks(.filter(member_root__in=list(roots)).values_list("id", flat=True))+ # Read by id with the rank checks in Python, since the rank filters steer Postgres onto the partial rank indexes.+ readable_scanners = {str(scanner_id) for scanner_id in scanner_ids}+ members = (+ accessible_observations(access, team_id, walkable.filter(id__in=member_ids))+ .values_list("id", "scanner_id", "watch_rank", person)+ .iterator()+ )+ reach_sessions: Counter[str] = Counter()+ reach_people: dict[str, set[str]] = {}+ for member_id, scanner_id, watch_rank, member_person in members:+ rank = current_rank({"watch_rank": watch_rank})+ if str(scanner_id) not in readable_scanners or rank is None or rank.get("category") not in categories:+ continue+ group = rank.get("group")+ root = str(group) if group is not None else str(member_id)+ reach_sessions[root] += 1+ reach_people.setdefault(root, set()).add(member_person)group_reach = {- row["watch_group_root"]: row- for row in accessible_observations(- access,- team_id,- current_ranks.filter(id__in=member_ids, watch_category__in=list(categories)),- )- .annotate(watch_group_root=group_root)- .values("watch_group_root")- .annotate(sessions=Count("id"), people=Count(person, distinct=True))+ root: {"sessions": sessions, "people": len(reach_people[root])} for root, sessions in reach_sessions.items()}# The row-gate reads each row's snapshot JSON, so it runs on the picks only.rows = cast(