posthog
posthog copied to clipboard
perf: Speed up filtering persons
Problem
Currently, we first group/argmax every single person, then we filter that result set down. It'd be much faster to filter first, then group by.
Changes
Filter first, then group by, then filter again to make sure the results are still correct.
The resulting query is a bit ugly (basically 3 sub queries) but it takes the filtering of the persons page for researchgate down from 80-90 seconds to 2 seconds!
Also removed the personsArgMaxVersion and optimizeJoinedFilters modifiers as those were making things more complicated and weren't relevant anymore.
👉 Stay up-to-date with PostHog coding conventions for a smoother review.