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(signals): read cached implementation PR flags in inbox filters (#124390)

Dylan Martinbaa9f88ff558
diff --git a/products/signals/backend/report_content_gates.py b/products/signals/backend/report_content_gates.py
index ace9ee7e1d4d..59a0696030a7 100644
--- a/products/signals/backend/report_content_gates.py
+++ b/products/signals/backend/report_content_gates.py
@@ -23,6 +23,7 @@ REPORT_METRICS_FLAG = "signals-report-metrics"
REPORT_MONITORING_FLAG = "signals-report-monitoring"
FIRST_REPORT_EMAIL_FLAG = "signals-first-report-email"
RESEARCH_REVIEWER_SELECTION_FLAG = "signals-research-reviewer-selection"
+INBOX_CACHED_FILTERS_FLAG = "signals-inbox-cached-filters"
def _organization_flag_enabled(
@@ -95,3 +96,9 @@ def team_report_monitoring_enabled(team_id: int) -> bool:
def team_research_reviewer_selection_enabled(team_id: int) -> bool:
return _team_flag_enabled(RESEARCH_REVIEWER_SELECTION_FLAG, team_id)
+
+
+def organization_inbox_cached_filters_enabled(organization_id: UUID) -> bool:
+ return _organization_flag_enabled(
+ INBOX_CACHED_FILTERS_FLAG, organization_id, enable_in_debug=False, only_evaluate_locally=True
+ )
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index c3ee575c9716..7addb0e0d80b 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -2146,15 +2146,16 @@ class TestSignalReportListAPI(APIBaseTest):
pr_merged: bool = False,
) -> SignalReportAssignment:
parts = pr_url.rstrip("/").split("/") if pr_url else []
- return SignalReportAssignment.all_teams.create(
- team=self.team,
- report=report,
- pr_url=pr_url,
- repository="/".join(parts[-4:-2]) if parts else None,
- pr_number=int(parts[-1]) if parts else None,
- pr_state=pr_state if pr_url else None,
- pr_merged=pr_merged,
- )
+ with self.captureOnCommitCallbacks(execute=True):
+ return SignalReportAssignment.all_teams.create(
+ team=self.team,
+ report=report,
+ pr_url=pr_url,
+ repository="/".join(parts[-4:-2]) if parts else None,
+ pr_number=int(parts[-1]) if parts else None,
+ pr_state=pr_state if pr_url else None,
+ pr_merged=pr_merged,
+ )
def test_implementation_pr_fields_come_from_assignment(self):
report = self._create_report()
@@ -2652,7 +2653,8 @@ class TestSignalReportListAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK
assert [row["id"] for row in response.json()["results"]] == [str(dismissed.id)]
- def test_needs_decision_includes_failures_without_an_actionability_judgment(self):
+ @parameterized.expand([("live_filters", False), ("cached_columns", True)])
+ def test_needs_decision_includes_failures_without_an_actionability_judgment(self, _name: str, cached: bool) -> None:
failed = self._create_report(title="Failed research", status=SignalReport.Status.FAILED)
actionable = self._create_report(title="Ready for a decision")
self._actionability_artefact(actionable, actionability="immediately_actionable")
@@ -2669,7 +2671,11 @@ class TestSignalReportListAPI(APIBaseTest):
failed_with_pr = self._create_report(title="Failed with a PR", status=SignalReport.Status.FAILED)
self._create_assignment(failed_with_pr, pr_url="https://github.com/org/repo/pull/43")
- response = self.client.get(self._list_url(view="needs_decision", scope="entire_project"))
+ with patch("products.signals.backend.views.organization_inbox_cached_filters_enabled", return_value=cached):
+ response = self.client.get(self._list_url(view="needs_decision", scope="entire_project"))
+ count_response = self.client.get(
+ self._list_url(view="needs_decision", scope="entire_project", count_only="true")
+ )
assert response.status_code == status.HTTP_200_OK
assert {row["id"] for row in response.json()["results"]} == {
@@ -2678,7 +2684,7 @@ class TestSignalReportListAPI(APIBaseTest):
str(needs_input.id),
str(failed_with_pr.id),
}
- response = self.client.get(self._list_url(view="needs_decision", scope="entire_project", count_only="true"))
+ response = count_response
assert response.status_code == status.HTTP_200_OK
assert response.json()["count"] == 4
diff --git a/products/signals/backend/test/test_signal_report_assignment_api.py b/products/signals/backend/test/test_signal_report_assignment_api.py
index aa9833c28523..b0ba6bcd2886 100644
--- a/products/signals/backend/test/test_signal_report_assignment_api.py
+++ b/products/signals/backend/test/test_signal_report_assignment_api.py
@@ -862,45 +862,51 @@ class TestSignalReportAssignmentAPI(APIBaseTest):
assert response.status_code == status.HTTP_404_NOT_FOUND
assert not SignalReportAssignment.all_teams.filter(report=report).exists()
- def test_unclaimed_filter_excludes_claims_and_open_prs(self):
+ @parameterized.expand([("live_filters", False), ("cached_columns", True)])
+ def test_unclaimed_filter_excludes_claims_and_open_prs(self, _name: str, cached: bool) -> None:
unclaimed = self._create_report(title="Unclaimed")
claimed = self._create_report(title="Claimed")
in_review = self._create_report(title="In review")
self.client.post(self._claim_url(claimed), data={}, format="json")
- SignalReportAssignment.all_teams.create(
- team=self.team,
- report=in_review,
- pr_url="https://github.com/PostHog/posthog/pull/123",
- repository="posthog/posthog",
- pr_number=123,
- pr_state=SignalReportAssignment.PrState.OPEN,
- )
- merged_assignment = self._create_report(title="Merged assignment")
- SignalReportAssignment.all_teams.create(
- team=self.team,
- report=merged_assignment,
- pr_url="https://github.com/PostHog/posthog/pull/124",
- repository="posthog/posthog",
- pr_number=124,
- pr_state=SignalReportAssignment.PrState.MERGED,
- pr_merged=True,
- )
- linked = {}
- for number, state in [(125, SignalReportPullRequest.State.OPEN), (126, SignalReportPullRequest.State.MERGED)]:
- report = self._create_report(title=f"Linked {state}")
- pr = SignalReportPullRequest.objects.create(
+ with self.captureOnCommitCallbacks(execute=True):
+ SignalReportAssignment.all_teams.create(
team=self.team,
+ report=in_review,
+ pr_url="https://github.com/PostHog/posthog/pull/123",
repository="posthog/posthog",
- number=number,
- url=f"https://github.com/PostHog/posthog/pull/{number}",
- state=state,
+ pr_number=123,
+ pr_state=SignalReportAssignment.PrState.OPEN,
)
- SignalReportArtefact.objects.create(
- team=self.team, report=report, type=SignalReportArtefact.ArtefactType.PULL_REQUEST, pull_request=pr
+ merged_assignment = self._create_report(title="Merged assignment")
+ SignalReportAssignment.all_teams.create(
+ team=self.team,
+ report=merged_assignment,
+ pr_url="https://github.com/PostHog/posthog/pull/124",
+ repository="posthog/posthog",
+ pr_number=124,
+ pr_state=SignalReportAssignment.PrState.MERGED,
+ pr_merged=True,
)
- linked[state] = report
+ linked = {}
+ for number, state in [
+ (125, SignalReportPullRequest.State.OPEN),
+ (126, SignalReportPullRequest.State.MERGED),
+ ]:
+ report = self._create_report(title=f"Linked {state}")
+ pr = SignalReportPullRequest.objects.create(
+ team=self.team,
+ repository="posthog/posthog",
+ number=number,
+ url=f"https://github.com/PostHog/posthog/pull/{number}",
+ state=state,
+ )
+ SignalReportArtefact.objects.create(
+ team=self.team, report=report, type=SignalReportArtefact.ArtefactType.PULL_REQUEST, pull_request=pr
+ )
+ linked[state] = report
- response = self.client.get(self._list_url(unclaimed="true"))
+ with patch("products.signals.backend.views.organization_inbox_cached_filters_enabled", return_value=cached):
+ response = self.client.get(self._list_url(unclaimed="true"))
assert response.status_code == status.HTTP_200_OK
ids = {row["id"] for row in response.json()["results"]}
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index c76649e85e4a..8d062bf9e0e3 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -186,7 +186,10 @@ from products.signals.backend.report_claims import (
reports_with_active_claim,
responsible_users,
)
-from products.signals.backend.report_content_gates import organization_report_monitoring_enabled
+from products.signals.backend.report_content_gates import (
+ organization_inbox_cached_filters_enabled,
+ organization_report_monitoring_enabled,
+)
from products.signals.backend.report_generation.research import ActionabilityChoice
from products.signals.backend.report_generation.resolve_reviewers import (
ReviewerPayloadIndex,
@@ -1529,6 +1532,12 @@ class SignalReportViewSet(
def _report_monitoring_enabled(self) -> bool:
return organization_report_monitoring_enabled(self.organization.id)
+ @cached_property
+ def _inbox_cached_filters(self) -> bool:
+ # Reads the cached report columns instead of the per-report authorship and PR-link
+ # subqueries. Behind a flag until the daily reconcile shows no drift.
+ return organization_inbox_cached_filters_enabled(self.organization.id)
+
def _resolved_read_statuses(self) -> frozenset[str]:
statuses = frozenset({SignalReport.Status.RESOLVED})
if not self._report_monitoring_enabled:
@@ -1685,7 +1694,9 @@ class SignalReportViewSet(
report_ids_with_prefix = fetch_report_ids_for_scout_prefix(self.team, scout_prefix)
return queryset.filter(id__in=report_ids_with_prefix)
- def _implementation_pr_report_filter(self):
+ def _implementation_pr_report_filter(self) -> Q:
+ if self._inbox_cached_filters:
+ return Q(has_implementation_pr=True)
return implementation_pr_report_filter(team_id=self.team.id)
def _apply_signal_report_implementation_pr_filter(self, queryset):
@@ -1704,7 +1715,11 @@ class SignalReportViewSet(
wants_unclaimed = self._bool_query_param("unclaimed")
if wants_unclaimed is None:
return queryset
- has_review_pr = implementation_pr_report_filter(team_id=self.team.id, active_only=True)
+ has_review_pr = (
+ Q(has_active_implementation_pr=True)
+ if self._inbox_cached_filters
+ else implementation_pr_report_filter(team_id=self.team.id, active_only=True)
+ )
is_unclaimed = (
~Q(status__in={SignalReport.Status.RESOLVED, SignalReport.Status.MONITORING})
& ~reports_with_active_claim(team_id=self.team_id)
@@ -2794,6 +2809,7 @@ class SignalReportViewSet(
)
list_span.set_attribute("signals.reports.list.count_only", count_only)
list_span.set_attribute("signals.reports.list.include_source_metadata", include_source_metadata)
+ list_span.set_attribute("signals.reports.list.cached_filters", self._inbox_cached_filters)
with tracer.start_as_current_span("signals.reports.list.queryset"):
queryset = self.filter_queryset(self.get_queryset())