From 0c0bb441601354e8aabb036c2ee03ee929165d91 Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Thu, 23 May 2024 22:36:41 +0200 Subject: [PATCH] Clarify `generate_insight_cache_key` as legacy function --- posthog/caching/calculate_results.py | 6 +++--- posthog/models/dashboard_tile.py | 4 ++-- posthog/models/insight.py | 2 +- posthog/models/test/test_insight_model.py | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/posthog/caching/calculate_results.py b/posthog/caching/calculate_results.py index 4437bc157b43b..42420061e59a2 100644 --- a/posthog/caching/calculate_results.py +++ b/posthog/caching/calculate_results.py @@ -31,7 +31,7 @@ from posthog.models.filters import PathFilter from posthog.models.filters.stickiness_filter import StickinessFilter from posthog.models.filters.utils import get_filter -from posthog.models.insight import generate_insight_cache_key +from posthog.models.insight import generate_insight_filters_hash from posthog.queries.funnels import ClickhouseFunnelTimeToConvert, ClickhouseFunnelTrends from posthog.queries.funnels.utils import get_funnel_order_class from posthog.queries.paths import Paths @@ -69,7 +69,7 @@ def calculate_cache_key(target: Union[DashboardTile, Insight]) -> Optional[str]: return query_runner.get_cache_key() if insight.filters: - return generate_insight_cache_key(insight, dashboard) + return generate_insight_filters_hash(insight, dashboard) return None @@ -174,7 +174,7 @@ def calculate_for_filter_based_insight( insight: Insight, dashboard: Optional[Dashboard] ) -> tuple[str, str, list | dict]: filter = get_filter(data=insight.dashboard_filters(dashboard), team=insight.team) - cache_key = generate_insight_cache_key(insight, dashboard) + cache_key = generate_insight_filters_hash(insight, dashboard) cache_type = get_cache_type(filter) tag_queries( diff --git a/posthog/models/dashboard_tile.py b/posthog/models/dashboard_tile.py index 9d39028e49bf0..59738ee2033fa 100644 --- a/posthog/models/dashboard_tile.py +++ b/posthog/models/dashboard_tile.py @@ -4,7 +4,7 @@ from django.utils import timezone from posthog.models.dashboard import Dashboard -from posthog.models.insight import generate_insight_cache_key +from posthog.models.insight import generate_insight_filters_hash from posthog.models.tagged_item import build_check @@ -105,7 +105,7 @@ def save(self, *args, **kwargs) -> None: if self.insight is not None: has_no_filters_hash = self.filters_hash is None if has_no_filters_hash and self.insight.filters != {}: - self.filters_hash = generate_insight_cache_key(self.insight, self.dashboard) + self.filters_hash = generate_insight_filters_hash(self.insight, self.dashboard) if "update_fields" in kwargs: kwargs["update_fields"].append("filters_hash") diff --git a/posthog/models/insight.py b/posthog/models/insight.py index 2b93b3c214d4f..c4d0c29b4929b 100644 --- a/posthog/models/insight.py +++ b/posthog/models/insight.py @@ -206,7 +206,7 @@ class Meta: @timed("generate_insight_cache_key") -def generate_insight_cache_key(insight: Insight, dashboard: Optional[Dashboard]) -> str: +def generate_insight_filters_hash(insight: Insight, dashboard: Optional[Dashboard]) -> str: try: dashboard_insight_filter = get_filter(data=insight.dashboard_filters(dashboard=dashboard), team=insight.team) candidate_filters_hash = generate_cache_key("{}_{}".format(dashboard_insight_filter.toJSON(), insight.team_id)) diff --git a/posthog/models/test/test_insight_model.py b/posthog/models/test/test_insight_model.py index 9fc61485f7453..2570a5e70f051 100644 --- a/posthog/models/test/test_insight_model.py +++ b/posthog/models/test/test_insight_model.py @@ -1,7 +1,7 @@ from django.db.utils import IntegrityError from posthog.models import Dashboard, Insight, Team -from posthog.models.insight import generate_insight_cache_key +from posthog.models.insight import generate_insight_filters_hash from posthog.test.base import BaseTest @@ -76,8 +76,8 @@ def test_dashboard_does_not_affect_filters_hash_with_absent_date_from(self) -> N insight = Insight.objects.create(team=self.team, filters={"date_from": "-30d"}) dashboard = Dashboard.objects.create(team=self.team, filters={}) - filters_hash_no_dashboard = generate_insight_cache_key(insight, None) - filters_hash_with_absent_date_from = generate_insight_cache_key(insight, dashboard) + filters_hash_no_dashboard = generate_insight_filters_hash(insight, None) + filters_hash_with_absent_date_from = generate_insight_filters_hash(insight, dashboard) assert filters_hash_no_dashboard == filters_hash_with_absent_date_from @@ -85,8 +85,8 @@ def test_dashboard_does_not_affect_filters_hash_with_null_date_from(self) -> Non insight = Insight.objects.create(team=self.team, filters={"date_from": "-30d"}) dashboard = Dashboard.objects.create(team=self.team, filters={"date_from": None}) - filters_hash_no_dashboard = generate_insight_cache_key(insight, None) - filters_hash_with_null_date_from = generate_insight_cache_key(insight, dashboard) + filters_hash_no_dashboard = generate_insight_filters_hash(insight, None) + filters_hash_with_null_date_from = generate_insight_filters_hash(insight, dashboard) assert filters_hash_no_dashboard == filters_hash_with_null_date_from @@ -94,8 +94,8 @@ def test_dashboard_with_date_from_changes_filters_hash(self) -> None: insight = Insight.objects.create(team=self.team, filters={"date_from": "-30d"}) dashboard = Dashboard.objects.create(team=self.team, filters={"date_from": "-90d"}) - filters_hash_one = generate_insight_cache_key(insight, None) - filters_hash_two = generate_insight_cache_key(insight, dashboard) + filters_hash_one = generate_insight_filters_hash(insight, None) + filters_hash_two = generate_insight_filters_hash(insight, dashboard) assert filters_hash_one != filters_hash_two