add better cache for getProfileId

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-08-08 22:02:13 +02:00
committed by Carl-Gerhard Lindesvärd
parent 7d703bcd80
commit b02cbb2946
3 changed files with 44 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ import {
toISOString,
} from '@openpanel/common';
import type { IServiceCreateEventPayload, IServiceEvent } from '@openpanel/db';
import { createEvent } from '@openpanel/db';
import { createEvent, getProfileIdCached } from '@openpanel/db';
import { getLastScreenViewFromProfileId } from '@openpanel/db/src/services/event.service';
import { eventsQueue, findJobByPrefix, sessionsQueue } from '@openpanel/queue';
import type {
@@ -47,7 +47,10 @@ export async function incomingEvent(job: Job<EventsQueuePayloadIncomingEvent>) {
};
// this will get the profileId from the alias table if it exists
const profileId = body.profileId ? String(body.profileId) : '';
const profileId = await getProfileIdCached({
profileId: body.profileId,
projectId,
});
const createdAt = new Date(body.timestamp);
const url = getProperty('__path');
const { path, hash, query, origin } = parsePath(url);