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)
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) filters_select_clause, filters_timestamps_clause, filters_having, action_filter_params = format_action_filters( self.filter) date_from, date_to, _ = parse_timestamps(self.filter, self.team.pk) distinct_ids = self.fetch_distinct_ids(date_from, date_to, limit, distinct_id_offset) query = SESSION_SQL.format( date_from=date_from, date_to=date_to, 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, { **action_filter_params, "team_id": self.team.pk, "limit": limit, "offset": offset, "distinct_ids": distinct_ids, }, ) 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 filter_sessions_by_recordings(self.team, result, self.filter), pagination
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
def calculate_list(self, filter: SessionsFilter, 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) return filter_sessions_by_recordings(team, result, filter)