From 26ea95f7281d5971dea895cc553aecc02a5e73a6 Mon Sep 17 00:00:00 2001 From: Brett Hoerner Date: Tue, 2 Jul 2024 14:29:23 -0600 Subject: [PATCH] feat(plugin-server): only write personless overrides when necessary (#23407) --- plugin-server/src/worker/ingestion/person-state.ts | 6 +++--- .../tests/worker/ingestion/person-state.test.ts | 14 ++------------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/plugin-server/src/worker/ingestion/person-state.ts b/plugin-server/src/worker/ingestion/person-state.ts index 3475bc669528a..6e0ac0202fa7f 100644 --- a/plugin-server/src/worker/ingestion/person-state.ts +++ b/plugin-server/src/worker/ingestion/person-state.ts @@ -529,12 +529,12 @@ export class PersonState { 'mergeDistinctIds-OneExists', async (tx) => { // See comment above about `distinctIdVersion` - const _insertedDistinctId = await this.db.addPersonlessDistinctIdForMerge( + const insertedDistinctId = await this.db.addPersonlessDistinctIdForMerge( this.teamId, distinctIdToAdd, tx ) - const distinctIdVersion = 1 // TODO: Once `posthog_personlessdistinctid` is backfilled: insertedDistinctId ? 0 : 1 + const distinctIdVersion = insertedDistinctId ? 0 : 1 await this.db.addDistinctId(existingPerson, distinctIdToAdd, distinctIdVersion, tx) return [existingPerson, Promise.resolve()] @@ -584,7 +584,7 @@ export class PersonState { // whether we can optimize away an override by doing a swap, or whether we // need to actually write an override. (But mostly we're being verbose for // documentation purposes) - let distinctId2Version = 1 // TODO: Once `posthog_personlessdistinctid` is backfilled, this should be = 0 + let distinctId2Version = 0 if (insertedDistinctId1 && insertedDistinctId2) { // We were the first to insert both (neither was used for Personless), so we // can use either as the primary Person UUID and create no overrides. diff --git a/plugin-server/tests/worker/ingestion/person-state.test.ts b/plugin-server/tests/worker/ingestion/person-state.test.ts index 06bd8086ead84..f8220ba9ba155 100644 --- a/plugin-server/tests/worker/ingestion/person-state.test.ts +++ b/plugin-server/tests/worker/ingestion/person-state.test.ts @@ -278,19 +278,9 @@ describe('PersonState.update()', () => { ]) ) - // old2 does have an override, because we are temporarily writing out unnecessary - // overrides while we backfill `posthog_personlessdistinctid` + // old2 has no override, because it wasn't in posthog_personlessdistinctid const chOverridesOld = await fetchOverridesForDistinctId('old2') - expect(chOverridesOld.length).toEqual(1) - expect(chOverridesOld).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - distinct_id: 'old2', - person_id: oldUserUuid, - version: 1, - }), - ]) - ) + expect(chOverridesOld.length).toEqual(0) }) it('force_upgrade works', async () => {