Skip to content

Commit

Permalink
[plugin-server] Revert "nicer handling of insert distinct id failure (P…
Browse files Browse the repository at this point in the history
  • Loading branch information
yakkomajuri authored Sep 14, 2021
1 parent e8503b1 commit b6f4978
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/utils/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,10 @@ export class DB {
distinctId: string
): Promise<ProducerRecord | void> {
const insertResult = await client.query(
'INSERT INTO posthog_persondistinctid (distinct_id, person_id, team_id) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING *',
'INSERT INTO posthog_persondistinctid (distinct_id, person_id, team_id) VALUES ($1, $2, $3) RETURNING *',
[distinctId, person.id, person.team_id]
)

// some other thread already added this ID
if (insertResult.rows.length === 0) {
return
}

const personDistinctIdCreated = insertResult.rows[0] as PersonDistinctId
if (this.kafkaProducer) {
return {
Expand Down
9 changes: 3 additions & 6 deletions src/worker/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ export class EventsProcessor {
try {
await this.db.addDistinctId(oldPerson, distinctId)
// Catch race case when somebody already added this distinct_id between .get and .addDistinctId
} catch (error) {
Sentry.captureException(error)
} catch {
// integrity error
if (retryIfFailed) {
// run everything again to merge the users if needed
Expand All @@ -328,8 +327,7 @@ export class EventsProcessor {
try {
await this.db.addDistinctId(newPerson, previousDistinctId)
// Catch race case when somebody already added this distinct_id between .get and .addDistinctId
} catch (error) {
Sentry.captureException(error)
} catch {
// integrity error
if (retryIfFailed) {
// run everything again to merge the users if needed
Expand All @@ -345,8 +343,7 @@ export class EventsProcessor {
distinctId,
previousDistinctId,
])
} catch (error) {
Sentry.captureException(error)
} catch {
// Catch race condition where in between getting and creating,
// another request already created this person
if (retryIfFailed) {
Expand Down

0 comments on commit b6f4978

Please sign in to comment.