def _query_events_list(self, filter: Filter, team: Team, request: Request, long_date_from: bool = False) -> List: limit = "LIMIT 101" conditions, condition_params = determine_event_conditions( { "after": (now() - timedelta(days=1)).isoformat(), "before": (now() + timedelta(seconds=5)).isoformat(), **request.GET.dict(), }, long_date_from, ) prop_filters, prop_filter_params = parse_prop_clauses(filter.properties, team.pk) if request.GET.get("action_id"): action = Action.objects.get(pk=request.GET["action_id"]) if action.steps.count() == 0: return [] action_query, params = format_action_filter(action) prop_filters += " AND {}".format(action_query) prop_filter_params = {**prop_filter_params, **params} if prop_filters != "": return sync_execute( SELECT_EVENT_WITH_PROP_SQL.format(conditions=conditions, limit=limit, filters=prop_filters), {"team_id": team.pk, **condition_params, **prop_filter_params}, ) else: return sync_execute( SELECT_EVENT_WITH_ARRAY_PROPS_SQL.format(conditions=conditions, limit=limit), {"team_id": team.pk, **condition_params}, )
def list(self, request: Request, *args: Any, **kwargs: Any) -> Response: if not endpoint_enabled(CH_EVENT_ENDPOINT, request.user.distinct_id): return super().list(request) team = request.user.team filter = Filter(request=request) if request.GET.get("after"): filter._date_from = request.GET["after"] if request.GET.get("before"): filter._date_to = request.GET["before"] limit = "LIMIT 101" conditions, condition_params = determine_event_conditions(request.GET.dict()) prop_filters, prop_filter_params = parse_prop_clauses("uuid", filter.properties, team) if prop_filters != "": query_result = sync_execute( SELECT_EVENT_WITH_PROP_SQL.format(conditions=conditions, limit=limit, filters=prop_filters), {"team_id": team.pk, **condition_params, **prop_filter_params}, ) else: query_result = sync_execute( SELECT_EVENT_WITH_ARRAY_PROPS_SQL.format(conditions=conditions, limit=limit), {"team_id": team.pk, **condition_params}, ) result = ClickhouseEventSerializer( query_result, many=True, context={ "elements": self._get_elements(query_result, team), "people": self._get_people(query_result, team), }, ).data if len(query_result) > 100: path = request.get_full_path() reverse = request.GET.get("orderBy", "-timestamp") != "-timestamp" next_url: Optional[str] = request.build_absolute_uri( "{}{}{}={}".format( path, "&" if "?" in path else "?", "after" if reverse else "before", query_result[99][3].strftime("%Y-%m-%dT%H:%M:%S.%fZ"), ) ) else: next_url = None return Response({"next": next_url, "results": result})
def list(self, request: Request, *args: Any, **kwargs: Any) -> Response: team = request.user.team assert team is not None filter = Filter(request=request) if request.GET.get("after"): filter._date_from = request.GET["after"] if request.GET.get("before"): filter._date_to = request.GET["before"] limit = "LIMIT 101" conditions, condition_params = determine_event_conditions(request.GET.dict()) prop_filters, prop_filter_params = parse_prop_clauses(filter.properties, team.pk) if request.GET.get("action_id"): action = Action.objects.get(pk=request.GET["action_id"]) if action.steps.count() == 0: return Response({"next": False, "results": []}) action_query, params = format_action_filter(action) prop_filters += " AND {}".format(action_query) prop_filter_params = {**prop_filter_params, **params} if prop_filters != "": query_result = sync_execute( SELECT_EVENT_WITH_PROP_SQL.format(conditions=conditions, limit=limit, filters=prop_filters), {"team_id": team.pk, **condition_params, **prop_filter_params}, ) else: query_result = sync_execute( SELECT_EVENT_WITH_ARRAY_PROPS_SQL.format(conditions=conditions, limit=limit), {"team_id": team.pk, **condition_params}, ) result = ClickhouseEventSerializer( query_result[0:100], many=True, context={"people": self._get_people(query_result, team),}, ).data if len(query_result) > 100: path = request.get_full_path() reverse = request.GET.get("orderBy", "-timestamp") != "-timestamp" next_url: Optional[str] = request.build_absolute_uri( "{}{}{}={}".format( path, "&" if "?" in path else "?", "after" if reverse else "before", query_result[99][3].strftime("%Y-%m-%dT%H:%M:%S.%fZ"), ) ) else: next_url = None return Response({"next": next_url, "results": result})
def list(self, request): team = request.user.team filter = Filter(request=request) limit = "LIMIT 100" if not filter._date_from and not filter._date_to else "" conditions, condition_params = determine_event_conditions(request.GET) prop_filters, prop_filter_params = parse_filter(filter.properties) if prop_filters: query_result = sync_execute( SELECT_EVENT_WITH_PROP_SQL.format(conditions=conditions, limit=limit, filters=prop_filters), {"team_id": team.pk, **condition_params, **prop_filter_params}, ) else: query_result = sync_execute( SELECT_EVENT_WITH_ARRAY_PROPS_SQL.format(conditions=conditions, limit=limit), {"team_id": team.pk, **condition_params}, ) result = ClickhouseEventSerializer(query_result, many=True, context={"elements": None, "people": None}).data return Response({"next": None, "results": result})