fix(buffer): do not update created_at for profiles since its our partition key
This commit is contained in:
@@ -4,7 +4,7 @@ import type { FastifyPluginCallback } from 'fastify';
|
|||||||
import { clientHook } from '@/hooks/client.hook';
|
import { clientHook } from '@/hooks/client.hook';
|
||||||
import { isBotHook } from '@/hooks/is-bot.hook';
|
import { isBotHook } from '@/hooks/is-bot.hook';
|
||||||
|
|
||||||
const trackRouter: FastifyPluginCallback = (fastify) => {
|
const trackRouter: FastifyPluginCallback = async (fastify) => {
|
||||||
fastify.addHook('preHandler', clientHook);
|
fastify.addHook('preHandler', clientHook);
|
||||||
fastify.addHook('preHandler', isBotHook);
|
fastify.addHook('preHandler', isBotHook);
|
||||||
|
|
||||||
|
|||||||
@@ -69,18 +69,11 @@ export class ProfileBuffer extends BaseBuffer {
|
|||||||
const existingProfile = await this.fetchProfile(profile, logger);
|
const existingProfile = await this.fetchProfile(profile, logger);
|
||||||
|
|
||||||
const mergedProfile: IClickhouseProfile = existingProfile
|
const mergedProfile: IClickhouseProfile = existingProfile
|
||||||
? deepMergeObjects(existingProfile, profile)
|
? deepMergeObjects(existingProfile, omit(['created_at'], profile))
|
||||||
: profile;
|
: profile;
|
||||||
|
|
||||||
// Avoid unnecessary updates:
|
if (profile && existingProfile) {
|
||||||
// If the profile is less than X minutes old
|
|
||||||
// and the profiles are the same
|
|
||||||
if (profile.created_at && existingProfile?.created_at) {
|
|
||||||
const a = new Date(profile.created_at);
|
|
||||||
const b = new Date(existingProfile.created_at);
|
|
||||||
const diffTime = Math.abs(a.getTime() - b.getTime());
|
|
||||||
if (
|
if (
|
||||||
diffTime < 1000 * 60 * 10 &&
|
|
||||||
shallowEqual(
|
shallowEqual(
|
||||||
omit(['created_at'], existingProfile),
|
omit(['created_at'], existingProfile),
|
||||||
omit(['created_at'], mergedProfile),
|
omit(['created_at'], mergedProfile),
|
||||||
|
|||||||
Reference in New Issue
Block a user