diff --git a/frontend/src/scenes/retention/queries.ts b/frontend/src/scenes/retention/queries.ts index a34c0c4ff9d2b..64b88372339db 100644 --- a/frontend/src/scenes/retention/queries.ts +++ b/frontend/src/scenes/retention/queries.ts @@ -6,7 +6,7 @@ import { ActorsQuery, NodeKind, RetentionQuery } from '~/queries/schema' export function retentionToActorsQuery(query: RetentionQuery, selectedInterval: number, offset = 0): ActorsQuery { const group = query.aggregation_group_type_index !== undefined const selectActor = group ? 'group' : 'person' - const totalIntervals = query.retentionFilter.total_intervals || 11 + const totalIntervals = (query.retentionFilter.total_intervals || 11) - selectedInterval const selects = Array.from({ length: totalIntervals }, (_, intervalNumber) => `interval_${intervalNumber}`) return { kind: NodeKind.ActorsQuery, @@ -36,7 +36,7 @@ export async function queryForActors( const response = await query(actorsQuery) const results: RetentionTableAppearanceType[] = response.results.map((row) => ({ person: row[0], - appearances: row.slice(1, row.length - 1), + appearances: row.slice(1, row.length), })) return { result: results, diff --git a/frontend/src/scenes/retention/retentionModalLogic.ts b/frontend/src/scenes/retention/retentionModalLogic.ts index ad605e13b1516..9aba029d17c2c 100644 --- a/frontend/src/scenes/retention/retentionModalLogic.ts +++ b/frontend/src/scenes/retention/retentionModalLogic.ts @@ -1,4 +1,6 @@ import { actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea' +import { FEATURE_FLAGS } from 'lib/constants' +import { featureFlagLogic } from 'lib/logic/featureFlagLogic' import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic' import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils' import { retentionToActorsQuery } from 'scenes/retention/queries' @@ -19,7 +21,14 @@ export const retentionModalLogic = kea([ key(keyForInsightLogicProps(DEFAULT_RETENTION_LOGIC_KEY)), path((key) => ['scenes', 'retention', 'retentionModalLogic', key]), connect((props: InsightLogicProps) => ({ - values: [insightVizDataLogic(props), ['querySource'], groupsModel, ['aggregationLabel']], + values: [ + insightVizDataLogic(props), + ['querySource'], + groupsModel, + ['aggregationLabel'], + featureFlagLogic, + ['featureFlags'], + ], actions: [retentionPeopleLogic(props), ['loadPeople']], })), actions(() => ({ @@ -56,9 +65,9 @@ export const retentionModalLogic = kea([ }, ], exploreUrl: [ - (s) => [s.actorsQuery], - (actorsQuery): string | null => { - if (!actorsQuery) { + (s) => [s.actorsQuery, s.featureFlags], + (actorsQuery, featureFlags): string | null => { + if (!actorsQuery || !featureFlags?.[FEATURE_FLAGS.HOGQL_INSIGHTS_RETENTION]) { return null } const query: DataTableNode = { diff --git a/posthog/hogql_queries/insights/retention_query_runner.py b/posthog/hogql_queries/insights/retention_query_runner.py index 9234b13a428d4..3a3bc4def3374 100644 --- a/posthog/hogql_queries/insights/retention_query_runner.py +++ b/posthog/hogql_queries/insights/retention_query_runner.py @@ -348,7 +348,7 @@ def to_actors_query(self, interval: Optional[int] = None) -> ast.SelectQuery: timings=self.timings, ) # We want to expose each interval as a separate column - for i in range(self.query_date_range.total_intervals): + for i in range(self.query_date_range.total_intervals - interval): retention_query.select.append( ast.Alias( alias=f"interval_{i}",