mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 09:16:49 +01:00
e5ee7b4270
* Run queries against person_distinct_id2 when async migration is done * Only write to clickhouse_person_unique_id topic if async migration is incomplete * Update query snapshots * Update plugin-server * Adjust caching logic
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from datetime import timedelta
|
|
|
|
from ee.clickhouse.materialized_columns.util import cache_for
|
|
from ee.clickhouse.sql.person import GET_TEAM_PERSON_DISTINCT_IDS, GET_TEAM_PERSON_DISTINCT_IDS_NEW_TABLE
|
|
from posthog.models.async_migration import is_async_migration_complete
|
|
from posthog.settings import BENCHMARK, TEST
|
|
|
|
using_new_table = TEST or BENCHMARK
|
|
|
|
|
|
def get_team_distinct_ids_query(team_id: int) -> str:
|
|
from ee.clickhouse.client import substitute_params
|
|
|
|
global using_new_table
|
|
|
|
using_new_table = using_new_table or _fetch_person_distinct_id2_ready()
|
|
|
|
if using_new_table:
|
|
return substitute_params(GET_TEAM_PERSON_DISTINCT_IDS_NEW_TABLE, {"team_id": team_id})
|
|
else:
|
|
return substitute_params(GET_TEAM_PERSON_DISTINCT_IDS, {"team_id": team_id})
|
|
|
|
|
|
is_ready = False
|
|
|
|
# :TRICKY: Avoid overly eagerly checking whether the migration is complete.
|
|
# We instead cache negative responses for a minute and a positive one forever.
|
|
def _fetch_person_distinct_id2_ready() -> bool:
|
|
global is_ready
|
|
|
|
if is_ready:
|
|
return True
|
|
is_ready = _fetch_person_distinct_id2_ready_cached()
|
|
return is_ready
|
|
|
|
|
|
@cache_for(timedelta(minutes=1))
|
|
def _fetch_person_distinct_id2_ready_cached() -> bool:
|
|
return is_async_migration_complete("0003_fill_person_distinct_id2")
|