: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
feat(autoresearch): cache team group types during serialization (#71849)
Paul D'Ambra14b5f8d2e139
diff --git a/posthog/api/team.py b/posthog/api/team.pyindex 5554c319c10f..1f18c244f25e 100644--- a/posthog/api/team.py+++ b/posthog/api/team.py@@ -754,6 +754,7 @@ def get_or_mint_live_events_token(team: Team, user_id: int | None) -> str:class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixin, UserAccessControlSerializerMixin):instance: Team | None+ _group_types_cache: list[dict[str, Any]] | None = Noneeffective_membership_level = serializers.SerializerMethodField()has_group_types = serializers.SerializerMethodField()@@ -850,11 +851,18 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixin@tracer.start_as_current_span("team_serializer.has_group_types")def get_has_group_types(self, team: Team) -> bool:- return bool(cached_group_types_for_team(team))+ return bool(self._get_group_types(team))@tracer.start_as_current_span("team_serializer.group_types")def get_group_types(self, team: Team) -> list[dict[str, Any]]:- return cached_group_types_for_team(team)+ return self._get_group_types(team)++ def _get_group_types(self, team: Team) -> list[dict[str, Any]]:+ group_types = self._group_types_cache+ if group_types is None:+ group_types = cached_group_types_for_team(team)+ self._group_types_cache = group_types+ return group_types@extend_schema_field(serializers.BooleanField())@tracer.start_as_current_span("team_serializer.events_retention_enforced")