: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
import { TeamManager } from '~/common/utils/team-manager'
import { createPrefetchStep } from '~/ingestion/common/steps/create-prefetch-step'
import { EventHeaders } from '~/types'
type PrefetchTeamsStepInput = { headers: Pick<EventHeaders, 'token'> }
/** Warms the team cache for the chunk's tokens ahead of resolveTeamStep's per-event lookups. */
export function prefetchTeamsStep<T extends PrefetchTeamsStepInput>(
teamManager: Pick<TeamManager, 'getTeamsByTokens'>,
enabled: boolean
) {
return createPrefetchStep<T, string>({
name: 'prefetchTeamsStep',
extractKey: (event) => event.headers.token || null,
load: (tokens) => teamManager.getTeamsByTokens(tokens, { flush: true }),
enabled,
})
}