fix(buffer): ensure we don't have duplicate events

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-27 12:48:43 +01:00
parent 9aa0ee485a
commit 44721f84da
4 changed files with 87 additions and 11 deletions

View File

@@ -229,11 +229,12 @@ async function track({
}) {
const isScreenView = payload.name === 'screen_view';
// this will ensure that we don't have multiple events creating sessions
const LOCK_DURATION = 1000;
const locked = await getRedisCache().set(
`request:priority:${currentDeviceId}-${previousDeviceId}:${isScreenView ? 'screen_view' : 'other'}`,
'locked',
'PX',
950, // a bit under the delay below
LOCK_DURATION,
'NX',
);
@@ -264,7 +265,7 @@ async function track({
// Prioritize 'screen_view' events by setting no delay
// This ensures that session starts are created from 'screen_view' events
// rather than other events, maintaining accurate session tracking
delay: isScreenView ? undefined : 1000,
delay: isScreenView ? undefined : LOCK_DURATION - 100,
},
);
}