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