Skip to content

feat(cdp): Use lazy loader for hog functions#30235

Merged
benjackwhite merged 3 commits intomasterfrom
revert/feat-lazy-load
Mar 21, 2025
Merged

feat(cdp): Use lazy loader for hog functions#30235
benjackwhite merged 3 commits intomasterfrom
revert/feat-lazy-load

Conversation

@benjackwhite
Copy link
Contributor

@benjackwhite benjackwhite commented Mar 20, 2025

Problem

Attempt number 3

Changes

  • Fixed the issues around filtering and groups parsing

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

@benjackwhite benjackwhite marked this pull request as ready for review March 21, 2025 10:01
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR reverts the lazy loading functionality for hog functions in the CDP component, focusing on fixing issues with filtering and groups parsing. Here are the key changes:

  • Removed HogFunctionManagerLazyService and its associated configuration flag, reverting to direct function loading through HogFunctionManagerService
  • Changed function reloading from reloadAllHogFunctions() to targeted onHogFunctionsReloaded(teamId, [itemId]) pattern
  • Added validation for group properties in GroupsManagerService to ensure group types and keys are strings
  • Modified service initialization order by removing explicit start()/stop() lifecycle methods from CdpApi
  • Improved parallel fetching of team hog functions and team data in _parseKafkaBatch for better performance

The changes appear to be a third attempt at implementing this feature, suggesting previous versions had issues that needed addressing. The removal of lazy loading aims to resolve problems with filtering and groups parsing while maintaining core functionality.

24 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

})
// Trigger the reload that django would do
await processor.hogFunctionManager.reloadAllHogFunctions()
processor['hogFunctionManager']['onHogFunctionsReloaded'](team.id, [item.id])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: accessing private members with bracket notation suggests these properties should potentially be protected instead of private for testing purposes

})
// Trigger the reload that django would do
await processor.hogFunctionManager.reloadAllHogFunctions()
processor['hogFunctionManager']['onHogFunctionsReloaded'](teamId, [item.id])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using private property access with ['hogFunctionManager'] is brittle. Consider exposing a public method for testing or using dependency injection.

Comment on lines 16 to 21
const insertHogFunction = async (hogFunction: Partial<HogFunctionType>) => {
const item = await _insertHogFunction(hub.postgres, team.id, hogFunction)
// Trigger the reload that django would do
await processor.hogFunctionManager.reloadAllHogFunctions()
processor['hogFunctionManager']['onHogFunctionsReloaded'](team.id, [item.id])
return item
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The insertHogFunction helper now uses private property access (['hogFunctionManager']['onHogFunctionsReloaded']) which makes the code brittle to refactoring. Consider exposing this as a public method or creating a test-specific interface.

Comment on lines +178 to +183
const [teamHogFunctions, team] = await Promise.all([
this.hogFunctionManager.getHogFunctionsForTeam(clickHouseEvent.team_id, [
'destination',
]),
this.hub.teamManager.fetchTeam(clickHouseEvent.team_id),
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Parallel fetching of team and functions could lead to race conditions if team is deleted between fetches. Consider fetching team first and early-returning if not found.


await manager.reloadAllHogFunctions()
const teamFunctions = manager.getTeamHogFunctions(teamId2)
manager['onHogFunctionsReloaded'](teamId2, [hogFunctions[2].id, hogFunctions[1].id])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Reloading with incorrect function IDs - using hogFunctions[2].id but working with teamId2 functions

@benjackwhite benjackwhite merged commit 924ee1d into master Mar 21, 2025
90 checks passed
@benjackwhite benjackwhite deleted the revert/feat-lazy-load branch March 21, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants