: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(analytics): stop the feed waiting for the unfiled sweep (#125156)
Matt Puaebdd35dc691f
diff --git a/frontend/src/scenes/analytics/analyticsFeedLogic.test.ts b/frontend/src/scenes/analytics/analyticsFeedLogic.test.tsindex 11a92bc68b08..532b050f5d57 100644--- a/frontend/src/scenes/analytics/analyticsFeedLogic.test.ts+++ b/frontend/src/scenes/analytics/analyticsFeedLogic.test.ts@@ -1,3 +1,4 @@+import { waitFor } from '@testing-library/react'import { expectLogic } from 'kea-test-utils'import { teamLogic } from 'scenes/teamLogic'@@ -41,11 +42,15 @@ const entry = (describe('analyticsFeedLogic', () => {let requests: string[]let searches: (string | null)[]+ let dashboardReads: number+ let firstDashboardRead: Promise<void>beforeEach(() => {resetAnalyticsFeedSnapshot()requests = []searches = []+ dashboardReads = 0+ firstDashboardRead = Promise.resolve()useMocks({get: {'/api/projects/:team_id/task_channels/': [],@@ -53,7 +58,7 @@ describe('analyticsFeedLogic', () => {requests.push('unfiled')return { count: 0 }},- '/api/projects/:team_id/file_system/': ({ request }) => {+ '/api/projects/:team_id/file_system/': async ({ request }) => {const params = new URL(request.url).searchParamsconst type = params.get('type') ?? params.get('type__startswith') ?? ''const offset = params.get('offset') ?? '0'@@ -79,6 +84,9 @@ describe('analyticsFeedLogic', () => {next: null,}}+ if (offset === '0' && ++dashboardReads === 1) {+ await firstDashboardRead+ }return offset === '0'? {results: [@@ -121,8 +129,6 @@ describe('analyticsFeedLogic', () => {'dashboard:3','notebook:n1',])- // The unfiled sweep runs once, before any source is read, so pre-sync objects get their rows.- expect(requests[0]).toBe('unfiled')expect(requests.filter((request) => request === 'unfiled')).toHaveLength(1)expect(requests.filter((request) => request !== 'unfiled').sort()).toEqual(['canvas:0:-created_at',@@ -144,6 +150,55 @@ describe('analyticsFeedLogic', () => {])})+ it('shows rows before the unfiled sweep returns, then reloads them once if the sweep filed any', async () => {+ let finishSweep: () => void = () => {}+ const sweepDone = new Promise<void>((resolve) => (finishSweep = resolve))+ useMocks({+ get: {+ '/api/projects/:team_id/file_system/unfiled/': async () => {+ requests.push('unfiled')+ await sweepDone+ return { count: 1 }+ },+ },+ })+ const logic = analyticsFeedLogic()+ logic.mount()++ await expectLogic(logic, () => logic.actions.refreshFeed(ALL)).toFinishAllListeners()+ expect(feed(logic)).toEqual(['dashboard:10', 'notebook:n9', 'dashboard:8'])+ expect(requests.filter((request) => request === 'dashboard:0:-created_at')).toHaveLength(1)++ finishSweep()+ await waitFor(() => expect(requests.filter((request) => request === 'dashboard:0:-created_at')).toHaveLength(2))+ await expectLogic(logic).toFinishAllListeners()++ expect(requests.filter((request) => request === 'unfiled')).toHaveLength(1)+ })++ it('reloads rows the sweep filed even while the first read is still in flight', async () => {+ let finishFirstRead: () => void = () => {}+ firstDashboardRead = new Promise<void>((resolve) => (finishFirstRead = resolve))+ useMocks({+ get: {+ '/api/projects/:team_id/file_system/unfiled/': () => {+ requests.push('unfiled')+ return { count: 1 }+ },+ },+ })+ const logic = analyticsFeedLogic()+ logic.mount()++ logic.actions.refreshFeed(ALL)+ await waitFor(() => expect(dashboardReads).toBe(2))+ finishFirstRead()+ await expectLogic(logic).toFinishAllListeners()++ expect(Object.values(logic.values.sources).some((source) => source.refreshing)).toBe(false)+ expect(feed(logic)).toEqual(['dashboard:10', 'notebook:n9', 'dashboard:8'])+ })+it.each([['another person, on the client alone', false, null],['the current person, on the server too', true, 'user:me'],diff --git a/frontend/src/scenes/analytics/analyticsFeedLogic.ts b/frontend/src/scenes/analytics/analyticsFeedLogic.tsindex 2cfe7a5615f1..d78df84fba4f 100644--- a/frontend/src/scenes/analytics/analyticsFeedLogic.ts+++ b/frontend/src/scenes/analytics/analyticsFeedLogic.ts@@ -227,8 +227,21 @@ export const analyticsFeedLogic = kea<analyticsFeedLogicType>([}// An object made before its product joined the file system has no row until the unfiled sweep// files it, and Today never opens the project tree that runs that sweep, so the first read runs it.- cache.unfiledSweep ??= api.fileSystem.unfiled().catch(() => null)- await cache.unfiledSweep+ // The sweep is slow in a large project, so the list does not wait for it and reloads only if it filed rows.+ if (!cache.unfiledSweep) {+ cache.unfiledSweep = api.fileSystem.unfiled().catch(() => null)+ void cache.unfiledSweep.then((result: { count: number } | null) => {+ if (!result?.count || cache.disposables.isDisposed) {+ return+ }+ // A new generation makes a read still in flight stale, so rows filed after it started are not lost.+ for (const [key, source] of Object.entries(values.sources)) {+ if (source.projectId === String(values.currentTeamId)) {+ actions.refreshSource(key, source.projectId, source.query, source.type)+ }+ }+ })+ }const projectId = String(values.currentTeamId)for (const type of analyticsFeedTypes(query)) {const key = analyticsSourceKey(projectId, query, type)