diff --git a/posthog/api/insight.py b/posthog/api/insight.py index cf9cac88959c77..13a54fe9637904 100644 --- a/posthog/api/insight.py +++ b/posthog/api/insight.py @@ -1103,7 +1103,12 @@ def funnel(self, request: request.Request, *args: Any, **kwargs: Any) -> Respons timings = HogQLTimings() try: with timings.measure("calculate"): - funnel = self.calculate_funnel(request) + query_method = get_query_method(request=request, team=self.team) + if query_method == "hogql": + funnel = self.calculate_funnel_hogql(request) + else: + funnel = self.calculate_funnel(request) + except ExposedHogQLError as e: raise ValidationError(str(e)) @@ -1134,6 +1139,19 @@ def calculate_funnel(self, request: request.Request) -> dict[str, Any]: "timezone": team.timezone, } + @cached_by_filters + def calculate_funnel_hogql(self, request: request.Request) -> dict[str, Any]: + team = self.team + filter = Filter(request=request, team=team) + query = filter_to_query(filter.to_dict()) + query_runner = get_query_runner(query, team, limit_context=None) + + # we use the legacy caching mechanism (@cached_by_filters decorator), no need to cache in the query runner + result = query_runner.run(execution_mode=ExecutionMode.CALCULATE_BLOCKING_ALWAYS) + # assert isinstance(result, schema.CachedFunnelsQueryResponse) + + return {"result": result.results, "timezone": team.timezone} + # ****************************************** # /projects/:id/insights/retention # params: