From 08b07e42fbdb0652830a262c44a8273ddef0e08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Thu, 6 Mar 2025 11:07:09 +0100 Subject: [PATCH] fix(buffer): do not update created_at for profiles since its our partition key --- apps/api/src/routes/track.router.ts | 2 +- packages/db/src/buffers/profile-buffer-redis.ts | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/apps/api/src/routes/track.router.ts b/apps/api/src/routes/track.router.ts index c2456db4..abc98844 100644 --- a/apps/api/src/routes/track.router.ts +++ b/apps/api/src/routes/track.router.ts @@ -4,7 +4,7 @@ import type { FastifyPluginCallback } from 'fastify'; import { clientHook } from '@/hooks/client.hook'; import { isBotHook } from '@/hooks/is-bot.hook'; -const trackRouter: FastifyPluginCallback = (fastify) => { +const trackRouter: FastifyPluginCallback = async (fastify) => { fastify.addHook('preHandler', clientHook); fastify.addHook('preHandler', isBotHook); diff --git a/packages/db/src/buffers/profile-buffer-redis.ts b/packages/db/src/buffers/profile-buffer-redis.ts index 3d44c1b4..1f70ccfe 100644 --- a/packages/db/src/buffers/profile-buffer-redis.ts +++ b/packages/db/src/buffers/profile-buffer-redis.ts @@ -69,18 +69,11 @@ export class ProfileBuffer extends BaseBuffer { const existingProfile = await this.fetchProfile(profile, logger); const mergedProfile: IClickhouseProfile = existingProfile - ? deepMergeObjects(existingProfile, profile) + ? deepMergeObjects(existingProfile, omit(['created_at'], profile)) : profile; - // Avoid unnecessary updates: - // 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 (profile && existingProfile) { if ( - diffTime < 1000 * 60 * 10 && shallowEqual( omit(['created_at'], existingProfile), omit(['created_at'], mergedProfile),