Exemple #1
0
    def calculate_list(self, filter: Filter, team: Team, limit: int,
                       offset: int):
        filters, params = parse_prop_clauses("uuid", filter.properties, team)

        if not filter._date_from:
            filter._date_from = timezone.now().replace(hour=0,
                                                       minute=0,
                                                       second=0,
                                                       microsecond=0)
        if not filter._date_to and filter.date_from:
            filter._date_to = filter.date_from + relativedelta(days=1)

        date_from, date_to = parse_timestamps(filter)
        params = {
            **params, "team_id": team.pk,
            "limit": limit,
            "offset": offset
        }
        query = SESSION_SQL.format(
            date_from=date_from,
            date_to=date_to,
            filters="{}".format(filters) if filter.properties else "",
            sessions_limit="LIMIT %(offset)s, %(limit)s",
        )
        query_result = sync_execute(query, params)
        result = self._parse_list_results(query_result)

        self._add_person_properties(team, result)

        return result
Exemple #2
0
    def run(self, filter: SessionsFilter, team: Team, *args,
            **kwargs) -> List[Dict[str, Any]]:
        limit = kwargs.get("limit", SESSIONS_LIST_DEFAULT_LIMIT)
        offset = kwargs.get("offset", 0)
        filter = set_default_dates(filter)

        filters, params = parse_prop_clauses(filter.properties, team.pk)
        action_filter_timestamp_sql, action_filter_params = format_action_filter_aggregate(
            filter, team.pk)

        date_from, date_to, _ = parse_timestamps(filter, team.pk)
        params = {
            **params,
            **action_filter_params,
            "team_id": team.pk,
            "limit": limit,
            "offset": offset,
            "distinct_id_limit": limit + offset,
        }
        query = SESSION_SQL.format(
            date_from=date_from,
            date_to=date_to,
            filters=filters,
            action_filter_timestamp=action_filter_timestamp_sql,
            sessions_limit="LIMIT %(offset)s, %(limit)s",
        )
        query_result = sync_execute(query, params)
        result = self._parse_list_results(query_result)

        self._add_person_properties(team, result)

        return filter_sessions_by_recordings(team, result, filter)
Exemple #3
0
    def fetch_page(self) -> Tuple[List[Session], Optional[Dict]]:
        limit = self.limit + 1
        self.filter = set_default_dates(self.filter)  # type: ignore
        offset = self.filter.pagination.get("offset", 0)
        distinct_id_offset = self.filter.pagination.get(
            "distinct_id_offset", 0)

        action_filters = format_action_filters(self.filter)

        date_from, date_to, date_params = parse_timestamps(
            self.filter, self.team.pk)
        distinct_ids = self.fetch_distinct_ids(action_filters, date_from,
                                               date_to, date_params, limit,
                                               distinct_id_offset)

        query = SESSION_SQL.format(
            date_from=date_from,
            date_to=date_to,
            filters_select_clause=action_filters.select_clause,
            matches_action_clauses=action_filters.matches_action_clauses,
            filters_having=action_filters.filters_having,
            sessions_limit="LIMIT %(offset)s, %(limit)s",
        )
        query_result = sync_execute(
            query,
            {
                **action_filters.params,
                "team_id": self.team.pk,
                "limit": limit,
                "offset": offset,
                "distinct_ids": distinct_ids,
                **date_params,
            },
        )
        result = self._parse_list_results(query_result)

        pagination = None
        if len(distinct_ids) >= limit + distinct_id_offset or len(
                result) == limit:
            if len(result) == limit:
                result.pop()
            pagination = {
                "offset": offset + len(result),
                "distinct_id_offset": distinct_id_offset + limit
            }

        self._add_person_properties(result)

        return join_with_session_recordings(self.team, result,
                                            self.filter), pagination
Exemple #4
0
    def calculate_list(self, filter: Filter, team: Team, limit: int, offset: int):
        filters, params = parse_prop_clauses(filter.properties, team.pk)

        date_from, date_to, _ = parse_timestamps(filter, team.pk)
        params = {**params, "team_id": team.pk, "limit": limit, "offset": offset, "distinct_id_limit": limit + offset}
        query = SESSION_SQL.format(
            date_from=date_from, date_to=date_to, filters=filters, sessions_limit="LIMIT %(offset)s, %(limit)s",
        )
        query_result = sync_execute(query, params)
        result = self._parse_list_results(query_result)

        self._add_person_properties(team, result)
        add_session_recording_ids(team, result)

        return result
Exemple #5
0
    def run(self, filter: SessionsFilter, team: Team, *args,
            **kwargs) -> Tuple[List[Session], Optional[Dict]]:
        limit = kwargs.get("limit", SESSIONS_LIST_DEFAULT_LIMIT) + 1
        offset = filter.pagination.get("offset", 0)
        filter = set_default_dates(filter)

        filters, params = parse_prop_clauses(filter.person_filter_properties,
                                             team.pk)
        filters_select_clause, filters_timestamps_clause, filters_having, action_filter_params = format_action_filters(
            filter)

        date_from, date_to, _ = parse_timestamps(filter, team.pk)
        params = {
            **params,
            **action_filter_params,
            "team_id": team.pk,
            "limit": limit,
            "offset": offset,
            "distinct_id_limit": limit + offset,
        }
        query = SESSION_SQL.format(
            date_from=date_from,
            date_to=date_to,
            filters=filters,
            filters_select_clause=filters_select_clause,
            filters_timestamps_clause=filters_timestamps_clause,
            filters_having=filters_having,
            sessions_limit="LIMIT %(offset)s, %(limit)s",
        )
        query_result = sync_execute(query, params)
        result = self._parse_list_results(query_result)

        pagination = None
        if len(result) == limit:
            result.pop()
            pagination = {"offset": offset + limit - 1}

        self._add_person_properties(team, result)

        return filter_sessions_by_recordings(team, result, filter), pagination