Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove memory leak from analytics #8839

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/server/utils/analytics/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {PARABOL_AI_USER_ID} from '../../../client/utils/constants'
import {ReasonToDowngradeEnum} from '../../../client/__generated__/DowngradeToStarterMutation.graphql'
import {PARABOL_AI_USER_ID} from '../../../client/utils/constants'
import {TeamLimitsEmailType} from '../../billing/helpers/sendTeamsLimitEmail'
import Meeting from '../../database/types/Meeting'
import {Team} from '../../postgres/queries/getTeamsByIds'
import MeetingMember from '../../database/types/MeetingMember'
import MeetingRetrospective from '../../database/types/MeetingRetrospective'
import MeetingTemplate from '../../database/types/MeetingTemplate'
import {Reactable} from '../../database/types/Reactable'
import {TaskServiceEnum} from '../../database/types/Task'
import getDataLoader from '../../graphql/getDataLoader'
import {ReactableEnum} from '../../graphql/private/resolverTypes'
import {IntegrationProviderServiceEnumType} from '../../graphql/types/IntegrationProviderServiceEnum'
import {UpgradeCTALocationEnumType} from '../../graphql/types/UpgradeCTALocationEnum'
import {TeamPromptResponse} from '../../postgres/queries/getTeamPromptResponsesByIds'
import {Team} from '../../postgres/queries/getTeamsByIds'
import {MeetingTypeEnum} from '../../postgres/types/Meeting'
import {MeetingSeries} from '../../postgres/types/MeetingSeries'
import {AmplitudeAnalytics} from './amplitude/AmplitudeAnalytics'
import {createMeetingProperties} from './helpers'
import {SegmentAnalytics} from './segment/SegmentAnalytics'
import {AmplitudeAnalytics} from './amplitude/AmplitudeAnalytics'
import getDataLoader from '../../graphql/getDataLoader'

export type MeetingSeriesAnalyticsProperties = Pick<
MeetingSeries,
Expand Down Expand Up @@ -483,9 +483,11 @@ class Analytics {
}

private track = (userId: string, event: AnalyticsEvent, properties?: Record<string, any>) => {
// in a perfect world we would pass in the existing dataloader since the user object is already cached in it
const dataloader = getDataLoader()
this.amplitudeAnalytics.track(userId, event, dataloader, properties)
this.segmentAnalytics.track(userId, event, dataloader, properties)
dataloader.dispose()
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/server/utils/segmentIo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ segmentIo.track = async (options: any, dataloader?: CacheWorker<DataLoaderBase>)
*/
const localDataloader = dataloader ?? getDataLoader()
const user = await localDataloader.get('users').load(userId)
if (localDataloader !== dataloader) {
// if it's new, dispose of it. if it's old, the GQL lifecycle will do that for us when it's ready
localDataloader.dispose()
}
const {email, segmentId} = user ?? {}
const properties = {...inProps, email}
return (segmentIo as any)._track({
Expand Down
Loading