From e3e114c5c14b4524105de0d74262688c4170e169 Mon Sep 17 00:00:00 2001 From: AndrMoura Date: Fri, 14 Jun 2024 15:59:51 +0100 Subject: [PATCH 1/4] add dialogs to insights without timeseries --- posthog/api/person.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/posthog/api/person.py b/posthog/api/person.py index f9a706016..4d741b2a7 100644 --- a/posthog/api/person.py +++ b/posthog/api/person.py @@ -714,10 +714,19 @@ def extend_actors_with_llm_events(self, filter, serialized_actors, request): distinct_ids = [di for sa in serialized_actors for di in sa["distinct_ids"]] ev = json.loads(req_dict["events"])[0].get("name") req_dict["event"] = ev + if "date_from" in req_dict: - req_dict["after"] = req_dict["date_from"] + if req_dict["date_from"] != "all": + req_dict["after"] = req_dict["date_from"] + else: + # for insights that do not contain timeseries. + # Insights with no timeseries add 'date_from = all' and no 'date_to' is sent + assert "date_to" not in req_dict, "date_to found when 'date_from = all'." + req_dict["before"] = datetime.today().strftime("%Y-%m-%d %H:%M:%S.%f") + if "date_to" in req_dict: req_dict["before"] = req_dict["date_to"] + req_dict["distinct_ids"] = distinct_ids query_result = query_events_list( @@ -802,7 +811,6 @@ def trends(self, request: request.Request, *args: Any, **kwargs: Any) -> Respons return self._respond_with_cached_results(self.calculate_trends_persons(request)) - @cached_by_filters def calculate_trends_persons( self, request: request.Request ) -> Dict[str, Tuple[List, Optional[str], Optional[str], int]]: From 44af315387602c62dcf88648b9d4bc549392cbfb Mon Sep 17 00:00:00 2001 From: AndrMoura Date: Mon, 17 Jun 2024 10:08:02 +0100 Subject: [PATCH 2/4] refactor date_from if --- posthog/api/person.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/posthog/api/person.py b/posthog/api/person.py index 4d741b2a7..edc525b02 100644 --- a/posthog/api/person.py +++ b/posthog/api/person.py @@ -716,13 +716,14 @@ def extend_actors_with_llm_events(self, filter, serialized_actors, request): req_dict["event"] = ev if "date_from" in req_dict: - if req_dict["date_from"] != "all": - req_dict["after"] = req_dict["date_from"] - else: - # for insights that do not contain timeseries. + if req_dict["date_from"] == "all": + # For insights that do not contain timeseries (piechart, number) # Insights with no timeseries add 'date_from = all' and no 'date_to' is sent + # we set a date that grabs all events before "now"s assert "date_to" not in req_dict, "date_to found when 'date_from = all'." req_dict["before"] = datetime.today().strftime("%Y-%m-%d %H:%M:%S.%f") + else: # -180d, -7d, other timestamps + req_dict["after"] = req_dict["date_from"] if "date_to" in req_dict: req_dict["before"] = req_dict["date_to"] From 96e8fa9aa2911af6c6653e5e4d8fc48d717a82cd Mon Sep 17 00:00:00 2001 From: AndrMoura Date: Fri, 13 Sep 2024 12:09:07 +0100 Subject: [PATCH 3/4] remove date_from and date_to in llm_events request --- posthog/api/person.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/posthog/api/person.py b/posthog/api/person.py index edc525b02..83784cbe1 100644 --- a/posthog/api/person.py +++ b/posthog/api/person.py @@ -715,19 +715,6 @@ def extend_actors_with_llm_events(self, filter, serialized_actors, request): ev = json.loads(req_dict["events"])[0].get("name") req_dict["event"] = ev - if "date_from" in req_dict: - if req_dict["date_from"] == "all": - # For insights that do not contain timeseries (piechart, number) - # Insights with no timeseries add 'date_from = all' and no 'date_to' is sent - # we set a date that grabs all events before "now"s - assert "date_to" not in req_dict, "date_to found when 'date_from = all'." - req_dict["before"] = datetime.today().strftime("%Y-%m-%d %H:%M:%S.%f") - else: # -180d, -7d, other timestamps - req_dict["after"] = req_dict["date_from"] - - if "date_to" in req_dict: - req_dict["before"] = req_dict["date_to"] - req_dict["distinct_ids"] = distinct_ids query_result = query_events_list( From 53cb9eec50674c783d04cbad64fe1174250858ba Mon Sep 17 00:00:00 2001 From: AndrMoura Date: Fri, 13 Sep 2024 12:20:48 +0100 Subject: [PATCH 4/4] add caching filter back --- posthog/api/person.py | 1 + 1 file changed, 1 insertion(+) diff --git a/posthog/api/person.py b/posthog/api/person.py index 83784cbe1..4cc51edb0 100644 --- a/posthog/api/person.py +++ b/posthog/api/person.py @@ -799,6 +799,7 @@ def trends(self, request: request.Request, *args: Any, **kwargs: Any) -> Respons return self._respond_with_cached_results(self.calculate_trends_persons(request)) + @cached_by_filters def calculate_trends_persons( self, request: request.Request ) -> Dict[str, Tuple[List, Optional[str], Optional[str], int]]: