Skip to content

Commit

Permalink
avoid numeric insights api for queries with hogql support
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Sep 19, 2023
1 parent 058ec48 commit 632cae6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { loaders } from 'kea-loaders'
import type { dataNodeLogicType } from './dataNodeLogicType'
import { AnyResponseType, DataNode, EventsQuery, EventsQueryResponse, PersonsNode, QueryTiming } from '~/queries/schema'
import { query } from '~/queries/query'
import { isInsightQueryNode, isEventsQuery, isPersonsNode } from '~/queries/utils'
import { isInsightQueryNode, isEventsQuery, isPersonsNode, isQueryWithHogQLSupport } from '~/queries/utils'
import { subscriptions } from 'kea-subscriptions'
import { objectsEqual, shouldCancelQuery, uuid } from 'lib/utils'
import clsx from 'clsx'
Expand All @@ -29,6 +29,8 @@ import { teamLogic } from 'scenes/teamLogic'
import equal from 'fast-deep-equal'
import { filtersToQueryNode } from '../InsightQuery/utils/filtersToQueryNode'
import { compareInsightQuery } from 'scenes/insights/utils/compareInsightQuery'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FEATURE_FLAGS } from 'lib/constants'

export interface DataNodeLogicProps {
key: string
Expand All @@ -52,7 +54,7 @@ const queryEqual = (a: DataNode, b: DataNode): boolean => {
export const dataNodeLogic = kea<dataNodeLogicType>([
path(['queries', 'nodes', 'dataNodeLogic']),
connect({
values: [userLogic, ['user'], teamLogic, ['currentTeamId']],
values: [userLogic, ['user'], teamLogic, ['currentTeamId'], featureFlagLogic, ['featureFlags']],
}),
props({ query: {} } as DataNodeLogicProps),
key((props) => props.key),
Expand Down Expand Up @@ -96,6 +98,7 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
}
if (
isInsightQueryNode(props.query) &&
!(values.hogQLInsightsFlagEnabled && isQueryWithHogQLSupport(props.query)) &&
props.cachedResults &&
props.cachedResults['id'] &&
props.cachedResults['filters'] &&
Expand Down Expand Up @@ -309,6 +312,10 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
() => [(_, props) => props.cachedResults ?? null],
(cachedResults: AnyResponseType | null): boolean => !!cachedResults,
],
hogQLInsightsFlagEnabled: [
(s) => [s.featureFlags],
(featureFlags) => featureFlags[FEATURE_FLAGS.HOGQL_INSIGHTS],
],
query: [(_, p) => [p.query], (query) => query],
newQuery: [
(s, p) => [p.query, s.response],
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
isTimeToSeeDataSessionsNode,
isHogQLQuery,
isInsightVizNode,
isLifecycleQuery,
isQueryWithHogQLSupport,
} from './utils'
import api, { ApiMethodOptions } from 'lib/api'
import { getCurrentTeamId } from 'lib/utils/logics'
Expand Down Expand Up @@ -114,7 +114,7 @@ export async function query<N extends DataNode = DataNode>(
try {
if (isPersonsNode(queryNode)) {
response = await api.get(getPersonsEndpoint(queryNode), methodOptions)
} else if (isInsightQueryNode(queryNode) && !(hogQLInsightsFlagEnabled && isLifecycleQuery(queryNode))) {
} else if (isInsightQueryNode(queryNode) && !(hogQLInsightsFlagEnabled && isQueryWithHogQLSupport(queryNode))) {
const filters = queryNodeToFilter(queryNode)
const params = {
...filters,
Expand Down

0 comments on commit 632cae6

Please sign in to comment.