fix(buffer): merge events in queue and get last screen view from buffer instead of cache

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-18 23:08:38 +01:00
parent 3fd4382c76
commit 8e94ce5877
4 changed files with 50 additions and 71 deletions

View File

@@ -579,35 +579,6 @@ export function getConversionEventNames(projectId: string) {
});
}
export async function getLastScreenViewFromProfileId({
profileId,
projectId,
}: {
profileId: string;
projectId: string;
}) {
if (!profileId) {
return null;
}
const eventInBuffer = await eventBuffer.getLastScreenView({
projectId,
profileId,
});
if (eventInBuffer) {
return eventInBuffer;
}
const [eventInDb] = profileId
? await getEvents(
`SELECT * FROM ${TABLE_NAMES.events} WHERE name = 'screen_view' AND profile_id = ${escape(profileId)} AND project_id = ${escape(projectId)} AND created_at >= now() - INTERVAL 30 MINUTE ORDER BY created_at DESC LIMIT 1`,
)
: [];
return eventInDb || null;
}
export async function getTopPages({
projectId,
cursor,