Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(insights): load home queries concurrently in the new navigation (#121170)

Daniel Parker2c3567726b4e
diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts
index 61b722f430c1..ca63d7c72e8c 100644
--- a/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts
+++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts
@@ -3,10 +3,12 @@ jest.unmock('lib/utils/concurrencyController')
import { expectLogic } from 'kea-test-utils'
import { promiseResolveReject } from 'lib/utils/async'
+import { sceneLogic } from 'scenes/sceneLogic'
+import { Scene } from 'scenes/sceneTypes'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { performQuery } from '~/queries/query'
-import { AccountsTableQueryResponse, NodeKind } from '~/queries/schema/schema-general'
+import { AccountsTableQueryResponse, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
jest.mock('~/queries/query', () => ({
@@ -22,6 +24,49 @@ describe('dataNodeLogic concurrency', () => {
initKeaTests()
})
+ it.each([Scene.SavedInsights, Scene.AnalyticsProductHome])(
+ 'starts six Home queries before starting a seventh in %s',
+ async (scene) => {
+ sceneLogic.mount()
+ sceneLogic.actions.setScene(scene, undefined, { params: {}, searchParams: {}, hashParams: {} })
+ const response: HogQLQueryResponse = { results: [], columns: [], types: [] }
+ const pendingResponses = Array.from({ length: 7 }, () => promiseResolveReject<HogQLQueryResponse>())
+ const seventhQueryStarted = promiseResolveReject<void>()
+ let nextResponse = 0
+ mockedQuery.mockImplementation(() => {
+ const pendingResponse = pendingResponses[nextResponse++]
+ if (nextResponse === 7) {
+ seventhQueryStarted.resolve()
+ }
+ return pendingResponse.promise
+ })
+ const logics = pendingResponses.map((_, index) =>
+ dataNodeLogic({
+ key: `home-${index}`,
+ query: { kind: NodeKind.HogQLQuery, query: `SELECT ${index}` },
+ loadPriority: index,
+ })
+ )
+
+ jest.useFakeTimers()
+ try {
+ logics.forEach((logic) => logic.mount())
+ jest.advanceTimersByTime(0)
+ expect(mockedQuery).toHaveBeenCalledTimes(6)
+
+ pendingResponses[0].resolve(response)
+ await seventhQueryStarted.promise
+ expect(mockedQuery).toHaveBeenCalledTimes(7)
+ } finally {
+ jest.useRealTimers()
+ pendingResponses.forEach(({ resolve }) => resolve(response))
+ await Promise.all(logics.map((logic) => expectLogic(logic).toFinishAllListeners()))
+ logics.forEach((logic) => logic.unmount())
+ sceneLogic.unmount()
+ }
+ }
+ )
+
it('starts two account table queries before starting a third', async () => {
const pendingResponses = [
promiseResolveReject<AccountsTableQueryResponse>(),
diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
index fb9ad4a76c0d..12a80ece564d 100644
--- a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
+++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
@@ -220,7 +220,7 @@ function getConcurrencyController(query: DataNode, currentTeam: TeamType): Concu
return marketingAnalyticsConcurrencyController
}
- if (activeScene === Scene.SavedInsights) {
+ if (activeScene === Scene.SavedInsights || activeScene === Scene.AnalyticsProductHome) {
return productAnalyticsHomeConcurrencyController
}