Skip to content

Commit

Permalink
feat(plugin-server): only write personless overrides when necessary (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner authored Jul 2, 2024
1 parent d45c5ee commit 26ea95f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
6 changes: 3 additions & 3 deletions plugin-server/src/worker/ingestion/person-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 2 additions & 12 deletions plugin-server/tests/worker/ingestion/person-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 26ea95f

Please sign in to comment.