From 6971d6fa95fdf3f3a939af7d55b9c3728a4d5dfe Mon Sep 17 00:00:00 2001 From: Marie <51697796+ijreilly@users.noreply.github.com> Date: Wed, 10 Jun 2026 16:46:50 +0200 Subject: [PATCH] Prevent self-hosting app from re-matching/re-creating people on no-op updates (#21406) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The match-telemetry-event-with-people logic function triggers on selfHostingUser.* (both created and updated) and unconditionally wrote personId back to the record on every run. Since the handler's own write produces an updated event — and the telemetry webhook also updates unrelated fields (name, serverUrl, etc.) on returning signups — the matching logic re-ran unnecessarily, querying people and writing on each pass. This adds an early-return guard so the handler only does work when there's actually something to match: Skip when the selfHostingUser is already linked (personId set) and the primary email hasn't changed. Still (re)match on first link and on genuine email changes — the legitimate reasons for listening on updated. The guard reads before.email.primaryEmail via an 'before' in properties narrowing so it stays type-safe across the create/update event union. --- .../internal/self-hosting/package.json | 2 +- .../match-telemetry-event-with-people.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/twenty-apps/internal/self-hosting/package.json b/packages/twenty-apps/internal/self-hosting/package.json index 92fc3b132b..1ed1c0cfb9 100644 --- a/packages/twenty-apps/internal/self-hosting/package.json +++ b/packages/twenty-apps/internal/self-hosting/package.json @@ -1,6 +1,6 @@ { "name": "self-hosting", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "engines": { "node": "^24.5.0", diff --git a/packages/twenty-apps/internal/self-hosting/src/logic-functions/match-telemetry-event-with-people.ts b/packages/twenty-apps/internal/self-hosting/src/logic-functions/match-telemetry-event-with-people.ts index 95d6c20472..90041be5cb 100644 --- a/packages/twenty-apps/internal/self-hosting/src/logic-functions/match-telemetry-event-with-people.ts +++ b/packages/twenty-apps/internal/self-hosting/src/logic-functions/match-telemetry-event-with-people.ts @@ -1,6 +1,11 @@ -import { defineLogicFunction, type DatabaseEventPayload, type ObjectRecordCreateEvent, type ObjectRecordUpdateEvent } from 'twenty-sdk/define'; import { SELF_HOSTING_USER_NAME_SINGULAR } from 'src/objects/selfHostingUser.object'; import { CoreApiClient } from 'twenty-client-sdk/core'; +import { + defineLogicFunction, + type DatabaseEventPayload, + type ObjectRecordCreateEvent, + type ObjectRecordUpdateEvent, +} from 'twenty-sdk/define'; type SelfHostingUser = { id: string; @@ -31,6 +36,17 @@ const handler = async ( return; } + const existingPersonId = params.properties.after.personId; + const previousEmail = + 'before' in params.properties + ? params.properties.before?.email?.primaryEmail + : undefined; + const emailChanged = previousEmail !== email; + + if (existingPersonId && !emailChanged) { + return; + } + const client = new CoreApiClient(); const { people } = await client.query({