PostHog / plugin-server

Service to process and save PostHog events, supporting JS/TS plugins at that
https://posthog.com
8 stars 5 forks source link

WIP create person with properties early when processing event #597

Closed yakkomajuri closed 3 years ago

yakkomajuri commented 3 years ago

Changes

Playing with the idea of removing all the createPerson calls deeper down in process-event in favor of creating a person with some initial properties early on to make sure it exists.

Putting it out as a WIP PR just to run the entire test stack more easily

Checklist

yakkomajuri commented 3 years ago

@macobo what do you think of this?

Currently there are a few places deeper down where we check if a person exists and create it if not.

This PR just makes sure we create a new person right away (with the right properties) if we see an ID we haven't seen before.

It makes sure we only do one query in these cases, so cutting queries when creating a person with properties in half.

The one tradeoff is that if the first event for a person is an $identify event AND the person is being identified to a non-existing person, we'll do a merge which we didn't need to do before.

We can achieve the same effect (person properties set with one query) without this tradeoff, but we'd need to add more special handling. I think things are much cleaner this way, where we always know we're operating on an existing person. Things are quite messy now since we create persons at all sorts of different levels.

Happy to take pushback though. Put this together quickly for feedback.

macobo commented 3 years ago

This is rather complex to understand - I feel like everything is getting tangled more and more and gets harder to understand every time.

Suggestion: Let's use a manager type object instead:

We avoid weirdness with different code branches intermingling due to db stuff that's going on. We might also be able to use this pattern for personFound which I think we currently do twice?

yakkomajuri commented 3 years ago

I'm certainly biased, but don't see how this adds complexity. It removes 3 calls to create a person deeper down the call stack and adds the persons properties right away on the first call in processEvent.

Your approach sounds great if all we had to do was create a person. We rely on persons existing though and do other operations to them throughout this code path, so executing this at the end wouldn't work.

Happy to spend some more time thinking about this though. Finishing up the work on set/set_once first

@macobo

tiina303 commented 3 years ago

will break into small prs in the merged repo