chore: improve user deletion flow

This commit is contained in:
Chris Anderson 2025-07-02 11:06:55 -05:00
parent 1cb7a72679
commit a5190a5be3
2 changed files with 10 additions and 9 deletions

View file

@ -20,6 +20,7 @@ export default (config: ClickhouseConfig) => {
wait_for_async_insert: 0,
async_insert_deduplicate: 1,
async_insert_busy_timeout_ms: 1000,
lightweight_deletes_sync: 0,
},
})
}

View file

@ -170,21 +170,21 @@ export const deleteUser = async (projectId: number, externalId: string): Promise
id: user.id,
})
// Delete the user events from ClickHouse
await UserEvent.clickhouse().delete('project_id = {projectId: UInt32} AND user_id = {userId: UInt32}', {
projectId,
userId: user.id,
})
// Delete the user events from the database
await UserEvent.delete(qb => qb.where('project_id', projectId)
.where('user_id', user.id),
)
// Delete the user from the database
await User.delete(qb => qb.where('project_id', projectId)
.where('id', user.id),
)
// Delete the user events from the database
await UserEvent.delete(qb => qb.where('project_id', projectId)
.where('user_id', user.id),
)
// Delete the user events from ClickHouse
await UserEvent.clickhouse().delete('project_id = {projectId: UInt32} AND user_id = {userId: UInt32}', {
projectId,
userId: user.id,
})
}
export const saveDevice = async (projectId: number, { external_id, anonymous_id, ...params }: DeviceParams, trx?: Transaction): Promise<Device | undefined> => {