mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 12:21:02 +01:00
46faa8fab2
* refactor: foss move properties to /posthog * refactor: move replication and materializtaion * refactor: move file * refactor: move test and journeys * refactor: move breakdown props * refactor: move query imports * refactor: move more ee dependencies * refactor: restore groupsjoinquery * fix: errors * refactor: no ee.clickhouse dependncies * try import tasks * refactor: move materialization * refactor: change foss split for column optimizer * run black * fix: imports * remove comment * Update snapshots * run black * skip isort * Update snapshots * format * more fixes * refactor(FOSS): split out paths query code (#10378) * refactor: move migrations * refactor: move idl * fix: move more imports * import adjustments * fix: test import * fix: test import * fix: remove restriction * refactor: split out paths query code * refactor: more code splitting * fix: types * refactor(FOSS): Setup such that FOSS is deployable (#10352) * refactor: move migrations * refactor: move idl * fix: move more imports * import adjustments * fix: test import * fix: test import * fix: remove restriction * fix import * refactor: add snapshost * subscription-import * fix: safe import Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
71 lines
2.8 KiB
Python
71 lines
2.8 KiB
Python
from typing import Dict, Optional, Tuple
|
|
|
|
from rest_framework import request, response
|
|
from rest_framework.decorators import action
|
|
|
|
from ee.clickhouse.queries.funnels.funnel_correlation_persons import FunnelCorrelationActors
|
|
from posthog.api.person import PersonViewSet, should_paginate
|
|
from posthog.constants import FUNNEL_CORRELATION_PERSON_LIMIT, FUNNEL_CORRELATION_PERSON_OFFSET, INSIGHT_FUNNELS
|
|
from posthog.decorators import cached_function
|
|
from posthog.models import Filter
|
|
from posthog.utils import format_query_params_absolute_url
|
|
|
|
|
|
class EnterprisePersonViewSet(PersonViewSet):
|
|
@action(methods=["GET", "POST"], url_path="funnel/correlation", detail=False)
|
|
def funnel_correlation(self, request: request.Request, **kwargs) -> response.Response:
|
|
if request.user.is_anonymous or not self.team:
|
|
return response.Response(data=[])
|
|
|
|
results_package = self.calculate_funnel_correlation_persons(request)
|
|
|
|
if not results_package:
|
|
return response.Response(data=[])
|
|
|
|
people, next_url, initial_url = results_package["result"]
|
|
|
|
return response.Response(
|
|
data={
|
|
"results": [{"people": people, "count": len(people)}],
|
|
"next": next_url,
|
|
"initial": initial_url,
|
|
"is_cached": results_package.get("is_cached"),
|
|
"last_refresh": results_package.get("last_refresh"),
|
|
}
|
|
)
|
|
|
|
@cached_function
|
|
def calculate_funnel_correlation_persons(
|
|
self, request: request.Request
|
|
) -> Dict[str, Tuple[list, Optional[str], Optional[str]]]:
|
|
if request.user.is_anonymous or not self.team:
|
|
return {"result": ([], None, None)}
|
|
|
|
filter = Filter(request=request, data={"insight": INSIGHT_FUNNELS}, team=self.team)
|
|
if not filter.correlation_person_limit:
|
|
filter = filter.with_data({FUNNEL_CORRELATION_PERSON_LIMIT: 100})
|
|
base_uri = request.build_absolute_uri("/")
|
|
actors, serialized_actors = FunnelCorrelationActors(
|
|
filter=filter, team=self.team, base_uri=base_uri
|
|
).get_actors()
|
|
_should_paginate = should_paginate(actors, filter.correlation_person_limit)
|
|
|
|
next_url = (
|
|
format_query_params_absolute_url(
|
|
request,
|
|
filter.correlation_person_offset + filter.correlation_person_limit,
|
|
offset_alias=FUNNEL_CORRELATION_PERSON_OFFSET,
|
|
limit_alias=FUNNEL_CORRELATION_PERSON_LIMIT,
|
|
)
|
|
if _should_paginate
|
|
else None
|
|
)
|
|
initial_url = format_query_params_absolute_url(request, 0)
|
|
|
|
# cached_function expects a dict with the key result
|
|
return {"result": (serialized_actors, next_url, initial_url)}
|
|
|
|
|
|
class LegacyEnterprisePersonViewSet(EnterprisePersonViewSet):
|
|
legacy_team_compatibility = True
|