Skip to content

Commit

Permalink
fix(plugin-server): add time component to person.force_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner committed Apr 26, 2024
1 parent d77bae8 commit 76c9b56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions plugin-server/src/worker/ingestion/person-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ export class PersonState {
// Ensure person properties don't propagate elsewhere, such as onto the event itself.
person.properties = {}

// See documentation on the field.
person.force_upgrade = true
if (this.timestamp > person.created_at.plus({ minutes: 1 })) {
// See documentation on the field.
//
// Note that we account for timestamp vs person creation time (with a little
// padding for good measure) to account for ingestion lag. It's possible for
// events to be processed after person creation even if they were sent prior
// to person creation, and the user did nothing wrong in that case.
person.force_upgrade = true
}

return person
}
Expand Down
9 changes: 6 additions & 3 deletions plugin-server/tests/worker/ingestion/person-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ describe('PersonState.update()', () => {
event: Partial<PluginEvent>,
customHub?: Hub,
processPerson = true,
lazyPersonCreation = false
lazyPersonCreation = false,
timestampParam = timestamp
) {
const fullEvent = {
team_id: teamId,
Expand All @@ -123,7 +124,7 @@ describe('PersonState.update()', () => {
fullEvent as any,
teamId,
event.distinct_id!,
timestamp,
timestampParam,
processPerson,
customHub ? customHub.db : hub.db,
lazyPersonCreation,
Expand Down Expand Up @@ -261,6 +262,7 @@ describe('PersonState.update()', () => {
// `force_upgrade=true` and real Person `uuid` and `created_at`
processPerson = false
const event_uuid = new UUIDT().toString()
const timestampParam = timestamp.plus({ minutes: 5 }) // Event needs to happen after Person creation
const fakePerson = await personState(
{
event: '$pageview',
Expand All @@ -270,7 +272,8 @@ describe('PersonState.update()', () => {
},
hubParam,
processPerson,
lazyPersonCreation
lazyPersonCreation,
timestampParam
).update()
await hub.db.kafkaProducer.flush()

Expand Down

0 comments on commit 76c9b56

Please sign in to comment.