From 822cebc5a8e44b9b930ab2db454631ccbc9382bb Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Tue, 26 Mar 2024 11:30:45 +0000 Subject: [PATCH] feat: don't clone replay event data (#21074) * feat: clone once not every * leeory j * make the tests pass --- .../session-recording/utils.ts | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugin-server/src/main/ingestion-queues/session-recording/utils.ts b/plugin-server/src/main/ingestion-queues/session-recording/utils.ts index 53ce953e5bd92..2c5637726743e 100644 --- a/plugin-server/src/main/ingestion-queues/session-recording/utils.ts +++ b/plugin-server/src/main/ingestion-queues/session-recording/utils.ts @@ -255,38 +255,34 @@ export const reduceRecordingMessages = (messages: IncomingRecordingMessage[]): I const reducedMessages: Record = {} for (const message of messages) { - const clonedMessage = cloneObject(message) - const key = `${clonedMessage.team_id}-${clonedMessage.session_id}` + const key = `${message.team_id}-${message.session_id}` if (!reducedMessages[key]) { - reducedMessages[key] = clonedMessage + reducedMessages[key] = cloneObject(message) } else { const existingMessage = reducedMessages[key] - for (const [windowId, events] of Object.entries(clonedMessage.eventsByWindowId)) { + for (const [windowId, events] of Object.entries(message.eventsByWindowId)) { if (existingMessage.eventsByWindowId[windowId]) { existingMessage.eventsByWindowId[windowId].push(...events) } else { existingMessage.eventsByWindowId[windowId] = events } } - existingMessage.metadata.rawSize += clonedMessage.metadata.rawSize + existingMessage.metadata.rawSize += message.metadata.rawSize // Update the events ranges existingMessage.metadata.lowOffset = Math.min( existingMessage.metadata.lowOffset, - clonedMessage.metadata.lowOffset + message.metadata.lowOffset ) existingMessage.metadata.highOffset = Math.max( existingMessage.metadata.highOffset, - clonedMessage.metadata.highOffset + message.metadata.highOffset ) // Update the events ranges - existingMessage.eventsRange.start = Math.min( - existingMessage.eventsRange.start, - clonedMessage.eventsRange.start - ) - existingMessage.eventsRange.end = Math.max(existingMessage.eventsRange.end, clonedMessage.eventsRange.end) + existingMessage.eventsRange.start = Math.min(existingMessage.eventsRange.start, message.eventsRange.start) + existingMessage.eventsRange.end = Math.max(existingMessage.eventsRange.end, message.eventsRange.end) } }