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(customer-analytics): run account queries concurrently (#103967)

Arthur Moreira de Deus2cb88f75e48d
diff --git a/docs/internal/customer-analytics/accounts-table.md b/docs/internal/customer-analytics/accounts-table.md
index 7931e46b0721..2894b4e5b899 100644
--- a/docs/internal/customer-analytics/accounts-table.md
+++ b/docs/internal/customer-analytics/accounts-table.md
@@ -1,5 +1,11 @@
# Accounts table
+## Query scheduling
+
+Account row and overview requests use a dedicated frontend queue with two concurrent slots.
+This lets both requests start together while preserving cancellation, priority ordering, and queueing for additional account table queries.
+Other query types keep their existing global or scene-specific concurrency limits.
+
## Unsaved filters and views
The Accounts list keeps unsaved filters when a user opens an account and returns to the list.
diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts
new file mode 100644
index 000000000000..61b722f430c1
--- /dev/null
+++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.concurrency.test.ts
@@ -0,0 +1,70 @@
+jest.unmock('lib/utils/concurrencyController')
+
+import { expectLogic } from 'kea-test-utils'
+
+import { promiseResolveReject } from 'lib/utils/async'
+
+import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
+import { performQuery } from '~/queries/query'
+import { AccountsTableQueryResponse, NodeKind } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+
+jest.mock('~/queries/query', () => ({
+ __esModules: true,
+ ...jest.requireActual('~/queries/query'),
+ performQuery: jest.fn(),
+}))
+
+const mockedQuery = performQuery as jest.MockedFunction<typeof performQuery>
+
+describe('dataNodeLogic concurrency', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ it('starts two account table queries before starting a third', async () => {
+ const pendingResponses = [
+ promiseResolveReject<AccountsTableQueryResponse>(),
+ promiseResolveReject<AccountsTableQueryResponse>(),
+ promiseResolveReject<AccountsTableQueryResponse>(),
+ ]
+ const thirdQueryStarted = promiseResolveReject<void>()
+ let nextResponse = 0
+ mockedQuery.mockImplementation(() => {
+ const pendingResponse = pendingResponses[nextResponse++]
+ if (nextResponse === 3) {
+ thirdQueryStarted.resolve()
+ }
+ return pendingResponse.promise
+ })
+
+ const logics = ['rows', 'overview', 'totals'].map((key) =>
+ dataNodeLogic({
+ key: `accounts-${key}`,
+ query: { kind: NodeKind.AccountsTableQuery, columns: [], filters: [] },
+ })
+ )
+
+ try {
+ logics.forEach((logic) => logic.mount())
+
+ expect(mockedQuery).toHaveBeenCalledTimes(2)
+
+ pendingResponses[0].resolve({
+ kind: NodeKind.AccountsTableQuery,
+ results: [],
+ hasMore: false,
+ limit: 100,
+ offset: 0,
+ })
+ await thirdQueryStarted.promise
+ expect(mockedQuery).toHaveBeenCalledTimes(3)
+ } finally {
+ pendingResponses.forEach(({ resolve }) =>
+ resolve({ kind: NodeKind.AccountsTableQuery, results: [], hasMore: false, limit: 100, offset: 0 })
+ )
+ await Promise.all(logics.map((logic) => expectLogic(logic).toFinishAllListeners()))
+ logics.forEach((logic) => logic.unmount())
+ }
+ })
+})
diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
index 123dd3eedd65..533c58048856 100644
--- a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
+++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
@@ -179,11 +179,16 @@ function sanitizeRefreshType(refresh: unknown): RefreshType | undefined {
}
const concurrencyController = new ConcurrencyController(1)
+const accountsTableConcurrencyController = new ConcurrencyController(2)
const webAnalyticsConcurrencyController = new ConcurrencyController(6)
const webAnalyticsPreAggConcurrencyController = new ConcurrencyController(6)
const marketingAnalyticsConcurrencyController = new ConcurrencyController(6)
function getConcurrencyController(query: DataNode, currentTeam: TeamType): ConcurrencyController {
+ if (isAccountsTableQuery(query)) {
+ return accountsTableConcurrencyController
+ }
+
const mountedSceneLogic = sceneLogic.findMounted()
const activeScene = mountedSceneLogic?.values.activeSceneId