Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(insights): deactivate series cache for retention and lifecycle insights #19851

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions frontend/src/scenes/insights/InsightNav/insightNavLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ describe('insightNavLogic', () => {
},
},
}
const retentionQuery: InsightVizNode = {
kind: NodeKind.InsightVizNode,
source: {
kind: NodeKind.RetentionQuery,
retentionFilter: {
returning_entity: {
id: 'returning',
name: 'returning',
type: 'events',
},
target_entity: {
id: 'target',
name: 'target',
type: 'events',
},
},
},
}
// const retentionQuery: InsightVizNode = {
// kind: NodeKind.InsightVizNode,
// source: {
// kind: NodeKind.RetentionQuery,
// retentionFilter: {
// returning_entity: {
// id: 'returning',
// name: 'returning',
// type: 'events',
// },
// target_entity: {
// id: 'target',
// name: 'target',
// type: 'events',
// },
// },
// },
// }

it('is initialized on mount', async () => {
await expectLogic(logic).toMatchValues({
Expand Down Expand Up @@ -246,28 +246,28 @@ describe('insightNavLogic', () => {
})
})

it('stores series from retention entities', async () => {
await expectLogic(logic, () => {
builtInsightDataLogic.actions.setQuery(retentionQuery)
}).toMatchValues({
queryPropertyCache: expect.objectContaining({
series: [
{
event: 'target',
kind: 'EventsNode',
math: 'total',
name: 'target',
},
{
event: 'returning',
kind: 'EventsNode',
math: 'total',
name: 'returning',
},
],
}),
})
})
// it('stores series from retention entities', async () => {
// await expectLogic(logic, () => {
// builtInsightDataLogic.actions.setQuery(retentionQuery)
// }).toMatchValues({
// queryPropertyCache: expect.objectContaining({
// series: [
// {
// event: 'target',
// kind: 'EventsNode',
// math: 'total',
// name: 'target',
// },
// {
// event: 'returning',
// kind: 'EventsNode',
// math: 'total',
// name: 'returning',
// },
// ],
// }),
// })
// })

it('updates query when navigating', async () => {
await expectLogic(logic, () => {
Expand Down
46 changes: 27 additions & 19 deletions frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { filterTestAccountsDefaultsLogic } from 'scenes/settings/project/filterTestAccountDefaultsLogic'

import { examples, TotalEventsTable } from '~/queries/examples'
import { actionsAndEventsToSeries } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { insightMap } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { getDisplay, getShowPercentStackView, getShowValueOnSeries } from '~/queries/nodes/InsightViz/utils'
import {
Expand Down Expand Up @@ -36,9 +35,10 @@ import {
isInsightQueryWithBreakdown,
isInsightQueryWithSeries,
isInsightVizNode,
isLifecycleQuery,
isRetentionQuery,
} from '~/queries/utils'
import { ActionFilter, InsightLogicProps, InsightType } from '~/types'
import { InsightLogicProps, InsightType } from '~/types'

import type { insightNavLogicType } from './insightNavLogicType'

Expand Down Expand Up @@ -256,22 +256,26 @@ export const insightNavLogic = kea<insightNavLogicType>([
const cachePropertiesFromQuery = (query: InsightQueryNode, cache: QueryPropertyCache | null): QueryPropertyCache => {
const newCache = JSON.parse(JSON.stringify(query)) as QueryPropertyCache

// set series (first two entries) from retention target and returning entity
if (isRetentionQuery(query)) {
const { target_entity, returning_entity } = query.retentionFilter || {}
const series = actionsAndEventsToSeries({
events: [
...(target_entity?.type === 'events' ? [target_entity as ActionFilter] : []),
...(returning_entity?.type === 'events' ? [returning_entity as ActionFilter] : []),
],
actions: [
...(target_entity?.type === 'actions' ? [target_entity as ActionFilter] : []),
...(returning_entity?.type === 'actions' ? [returning_entity as ActionFilter] : []),
],
})
if (series.length > 0) {
newCache.series = [...series, ...(cache?.series ? cache.series.slice(series.length) : [])]
}
// // set series (first two entries) from retention target and returning entity
// if (isRetentionQuery(query)) {
// const { target_entity, returning_entity } = query.retentionFilter || {}
// const series = actionsAndEventsToSeries({
// events: [
// ...(target_entity?.type === 'events' ? [target_entity as ActionFilter] : []),
// ...(returning_entity?.type === 'events' ? [returning_entity as ActionFilter] : []),
// ],
// actions: [
// ...(target_entity?.type === 'actions' ? [target_entity as ActionFilter] : []),
// ...(returning_entity?.type === 'actions' ? [returning_entity as ActionFilter] : []),
// ],
// })
// if (series.length > 0) {
// newCache.series = [...series, ...(cache?.series ? cache.series.slice(series.length) : [])]
// }
// }

if (isLifecycleQuery(query)) {
newCache.series = cache?.series
}

// store the insight specific filter in commonFilter
Expand All @@ -292,7 +296,11 @@ const mergeCachedProperties = (query: InsightQueryNode, cache: QueryPropertyCach
// series
if (isInsightQueryWithSeries(mergedQuery)) {
if (cache.series) {
mergedQuery.series = cache.series
if (isLifecycleQuery(mergedQuery)) {
mergedQuery.series = cache.series.slice(0, 1)
} else {
mergedQuery.series = cache.series
}
} else if (cache.retentionFilter?.target_entity || cache.retentionFilter?.returning_entity) {
mergedQuery.series = [
...(cache.retentionFilter.target_entity
Expand Down
Loading