Skip to content

Commit

Permalink
perf: Move cohort calculation queries to offline workload (#22968)
Browse files Browse the repository at this point in the history
* move meaty query to offline

* also move `get_cohort_size` to offline
  • Loading branch information
tkaemming authored Jun 14, 2024
1 parent bf5b0be commit ca09980
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions posthog/models/cohort/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.utils import timezone
from rest_framework.exceptions import ValidationError

from posthog.clickhouse.client.connection import Workload
from posthog.clickhouse.query_tagging import tag_queries
from posthog.client import sync_execute
from posthog.constants import PropertyOperatorType
Expand Down Expand Up @@ -324,6 +325,7 @@ def recalculate_cohortpeople(
"new_version": pending_version,
},
settings={"optimize_on_insert": 0},
workload=Workload.OFFLINE,
)

count = get_cohort_size(cohort, override_version=pending_version)
Expand Down Expand Up @@ -370,6 +372,7 @@ def get_cohort_size(cohort: Cohort, override_version: Optional[int] = None) -> O
"version": override_version if override_version is not None else cohort.version,
"team_id": cohort.team_id,
},
workload=Workload.OFFLINE,
)

if count_result and len(count_result) and len(count_result[0]):
Expand Down

0 comments on commit ca09980

Please sign in to comment.