: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
chore(cdp): remove unused ActionManagerCDP (#88693)
Ben Whiteb9db00bc921e
diff --git a/nodejs/src/common/utils/action-manager-cdp.test.ts b/nodejs/src/common/utils/action-manager-cdp.test.tsdeleted file mode 100644index 237aaee75815..000000000000--- a/nodejs/src/common/utils/action-manager-cdp.test.ts+++ /dev/null@@ -1,178 +0,0 @@-import { createAction, createTeam, createTestTeamFixture } from '~/tests/helpers/sql'-import { Hub, Team } from '~/types'--import { defaultConfig } from '../config/config'-import { ActionManagerCDP } from './action-manager-cdp'-import { closeHub, createHub } from './db/hub'-import { PostgresRouter } from './db/postgres'--describe('ActionManagerCDP()', () => {- let hub: Hub- let actionManager: ActionManagerCDP- let postgres: PostgresRouter- let teamId: Team['id']- let fetchActionsSpy: jest.SpyInstance-- beforeEach(async () => {- const now = Date.now()- jest.spyOn(Date, 'now').mockImplementation(() => now)-- hub = await createHub()-- postgres = new PostgresRouter(defaultConfig)- actionManager = new ActionManagerCDP(postgres)- teamId = (await createTestTeamFixture(hub.postgres)).team.id- fetchActionsSpy = jest.spyOn(actionManager as any, 'fetchActions')- })-- afterEach(async () => {- await closeHub(hub)- })-- describe('getActionsForTeam()', () => {- it('returns empty array if no actions exist', async () => {- const result = await actionManager.getActionsForTeam(teamId)- expect(result).toEqual([])- })-- it('returns actions for a team', async () => {- const bytecode = ['_H', 1, 32, 'Chrome', 32, '$browser', 32, 'properties', 1, 2, 11]-- // Create an action- const actionId = await createAction(postgres, teamId, 'Test Action', bytecode)-- const result = await actionManager.getActionsForTeam(teamId)- expect(result).toHaveLength(1)- expect(result[0]).toMatchObject({- id: actionId,- name: 'Test Action',- team_id: teamId,- deleted: false,- bytecode,- bytecode_error: null,- })- })-- it('filters out deleted actions', async () => {- const bytecode = ['_H', 1, 32, 'Chrome', 32, '$browser', 32, 'properties', 1, 2, 11]-- // Create active action- await createAction(postgres, teamId, 'Active Action', bytecode)-- // Create deleted action- await createAction(postgres, teamId, 'Deleted Action', bytecode, { deleted: true })-- const result = await actionManager.getActionsForTeam(teamId)- expect(result).toHaveLength(1)- expect(result[0].name).toBe('Active Action')- })-- it('filters out actions without bytecode', async () => {- // Create action without bytecode- await createAction(postgres, teamId, 'No Bytecode Action', null)-- const result = await actionManager.getActionsForTeam(teamId)- expect(result).toEqual([])- })-- it('caches actions for subsequent calls', async () => {- const bytecode = ['_H', 1, 32, 'Chrome', 32, '$browser', 32, 'properties', 1, 2, 11]-- await createAction(postgres, teamId, 'Cached Action', bytecode)-- // First call- const result1 = await actionManager.getActionsForTeam(teamId)- expect(result1).toHaveLength(1)- expect(fetchActionsSpy).toHaveBeenCalledTimes(1)-- // Second call should use cache- const result2 = await actionManager.getActionsForTeam(teamId)- expect(result2).toHaveLength(1)- expect(fetchActionsSpy).toHaveBeenCalledTimes(1)- })-- it('returns empty array for non-existent team', async () => {- const result = await actionManager.getActionsForTeam(99999)- expect(result).toEqual([])- })- })-- describe('getActionsForTeams()', () => {- it('returns actions for multiple teams', async () => {- const bytecode = ['_H', 1, 32, 'Chrome', 32, '$browser', 32, 'properties', 1, 2, 11]-- // Create another team- const team = await hub.teamManager.getTeam(teamId)- const team2Id = await createTeam(postgres, team!.organization_id)-- // Create actions for both teams- await createAction(postgres, teamId, 'Team 1 Action', bytecode)- await createAction(postgres, team2Id, 'Team 2 Action', bytecode)-- const result = await actionManager.getActionsForTeams([teamId, team2Id])- expect(result[String(teamId)]).toHaveLength(1)- expect(result[String(teamId)]![0].name).toBe('Team 1 Action')- expect(result[String(team2Id)]).toHaveLength(1)- expect(result[String(team2Id)]![0].name).toBe('Team 2 Action')- })-- it('returns empty arrays for teams with no actions', async () => {- const result = await actionManager.getActionsForTeams([teamId, 99999])- expect(result[String(teamId)]).toEqual([])- expect(result['99999']).toEqual([])- })-- it('efficiently loads multiple teams with single database call', async () => {- const bytecode = ['_H', 1, 32, 'Chrome', 32, '$browser', 32, 'properties', 1, 2, 11]-- await createAction(postgres, teamId, 'Test Action', bytecode)-- const promises = [- actionManager.getActionsForTeam(teamId),- actionManager.getActionsForTeam(teamId),- actionManager.getActionsForTeam(99999),- ]-- const results = await Promise.all(promises)- expect(fetchActionsSpy).toHaveBeenCalledTimes(1)- expect(results[0]).toHaveLength(1)- expect(results[1]).toHaveLength(1)- expect(results[2]).toHaveLength(0)- })- })-- describe('fetchActions()', () => {- it('handles empty team ID array', async () => {- const result = await (actionManager as any).fetchActions([])- expect(result).toEqual({})- })-- it('handles invalid team IDs', async () => {- const result = await (actionManager as any).fetchActions(['invalid', 'NaN'])- expect(result).toEqual({})- })-- it('orders actions by team_id and updated_at DESC', async () => {- const bytecode = ['_H', 1, 32, 'test']-- // Create actions with different updated_at times- const olderTime = new Date(Date.now() - 3600000).toISOString() // 1 hour ago- const newerTime = new Date().toISOString()-- await createAction(postgres, teamId, 'Older Action', bytecode, {- created_at: olderTime,- updated_at: olderTime,- })-- await createAction(postgres, teamId, 'Newer Action', bytecode, {- created_at: newerTime,- updated_at: newerTime,- })-- const result = await actionManager.getActionsForTeam(teamId)- expect(result).toHaveLength(2)- expect(result[0].name).toBe('Newer Action') // Should be first due to DESC order- expect(result[1].name).toBe('Older Action')- })- })-})diff --git a/nodejs/src/common/utils/action-manager-cdp.ts b/nodejs/src/common/utils/action-manager-cdp.tsdeleted file mode 100644index a71c0c576da5..000000000000--- a/nodejs/src/common/utils/action-manager-cdp.ts+++ /dev/null@@ -1,86 +0,0 @@-import { coerceActionIds } from './coerce-action-ids'-import { PostgresRouter, PostgresUse } from './db/postgres'-import { LazyLoader } from './lazy-loader'--export interface Action {- id: number- name: string- team_id: number- deleted: boolean- bytecode: any- bytecode_error: string | null- steps_json: any- created_at: string- updated_at: string-}--export class ActionManagerCDP {- private lazyLoader: LazyLoader<Action[]>-- constructor(private postgres: PostgresRouter) {- this.lazyLoader = new LazyLoader({- name: 'ActionManagerCDP',- refreshAgeMs: 5 * 60 * 1000, // 5 minutes- refreshJitterMs: 60 * 1000, // 1 minute- loader: async (teamIds: string[]) => {- return await this.fetchActions(teamIds)- },- })- }-- public async getActionsForTeam(teamId: number): Promise<Action[]> {- const actions = await this.lazyLoader.get(String(teamId))- return actions || []- }-- public async getActionsForTeams(teamIds: number[]): Promise<Record<string, Action[] | null>> {- return this.lazyLoader.getMany(teamIds.map(String))- }-- private async fetchActions(teamIds: string[]): Promise<Record<string, Action[]>> {- const teamIdNumbers = teamIds.map(Number).filter((id) => !isNaN(id))-- if (teamIdNumbers.length === 0) {- return {}- }-- const result = await this.postgres.query<Action>(- PostgresUse.COMMON_READ,- `SELECT- id,- name,- team_id,- deleted,- bytecode,- bytecode_error,- steps_json,- created_at,- updated_at- FROM posthog_action- WHERE team_id = ANY($1) AND deleted = FALSE- AND bytecode IS NOT NULL- ORDER BY team_id, updated_at DESC- `,- [teamIdNumbers],- 'fetch-actions-by-team'- )-- // Initialize result record with empty arrays for all requested team IDs- const resultRecord: Record<string, Action[]> = {}- for (const teamId of teamIds) {- resultRecord[teamId] = []- }-- // Group actions by team_id- result.rows.forEach((action) => {- coerceActionIds(action)- const teamIdStr = String(action.team_id)- if (!resultRecord[teamIdStr]) {- resultRecord[teamIdStr] = []- }- resultRecord[teamIdStr].push(action)- })-- return resultRecord- }-}