improve(buffer): don't add profile if its from an event and already created
This commit is contained in:
@@ -53,7 +53,7 @@ export class ProfileBuffer extends BaseBuffer {
|
||||
return `${this.redisProfilePrefix}${projectId}:${profileId}`;
|
||||
}
|
||||
|
||||
async add(profile: IClickhouseProfile) {
|
||||
async add(profile: IClickhouseProfile, isFromEvent = false) {
|
||||
const logger = this.logger.child({
|
||||
projectId: profile.project_id,
|
||||
profileId: profile.id,
|
||||
@@ -64,6 +64,11 @@ export class ProfileBuffer extends BaseBuffer {
|
||||
|
||||
const existingProfile = await this.fetchFromCache(profile, logger);
|
||||
|
||||
if (isFromEvent && existingProfile) {
|
||||
logger.debug('Profile already created, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
const mergedProfile: IClickhouseProfile = existingProfile
|
||||
? deepMergeObjects(existingProfile, profile)
|
||||
: profile;
|
||||
|
||||
@@ -303,7 +303,7 @@ export async function createEvent(payload: IServiceCreateEventPayload) {
|
||||
profile.isExternal ||
|
||||
(profile.isExternal === false && payload.name === 'session_start')
|
||||
) {
|
||||
await upsertProfile(profile);
|
||||
await upsertProfile(profile, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,27 +212,33 @@ export async function createProfileAlias({
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertProfile({
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
email,
|
||||
avatar,
|
||||
properties,
|
||||
projectId,
|
||||
isExternal,
|
||||
}: IServiceUpsertProfile) {
|
||||
return profileBuffer.add({
|
||||
export async function upsertProfile(
|
||||
{
|
||||
id,
|
||||
first_name: firstName!,
|
||||
last_name: lastName!,
|
||||
email: email!,
|
||||
avatar: avatar!,
|
||||
properties: properties as Record<string, string | undefined>,
|
||||
project_id: projectId,
|
||||
created_at: formatClickhouseDate(new Date()),
|
||||
is_external: isExternal,
|
||||
});
|
||||
firstName,
|
||||
lastName,
|
||||
email,
|
||||
avatar,
|
||||
properties,
|
||||
projectId,
|
||||
isExternal,
|
||||
}: IServiceUpsertProfile,
|
||||
isFromEvent = false,
|
||||
) {
|
||||
return profileBuffer.add(
|
||||
{
|
||||
id,
|
||||
first_name: firstName!,
|
||||
last_name: lastName!,
|
||||
email: email!,
|
||||
avatar: avatar!,
|
||||
properties: properties as Record<string, string | undefined>,
|
||||
project_id: projectId,
|
||||
created_at: formatClickhouseDate(new Date()),
|
||||
is_external: isExternal,
|
||||
},
|
||||
isFromEvent,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getProfileId({
|
||||
|
||||
Reference in New Issue
Block a user