Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions posthog/settings/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@
BEHAVIORAL_BACKFILL_FINALIZER_MAX_RUNS_PER_PASS: int = get_from_env(
"BEHAVIORAL_BACKFILL_FINALIZER_MAX_RUNS_PER_PASS", 500, type_cast=int
)
# Kill switch for incremental cohort dependency cache maintenance. Off, every cohort create, delete,
# and dependency change rescans the whole team, which is the cost the incremental path removes. The
# fallback exists because a wrong incremental update only shows up as a shorter recalculation chain,
# which no dashboard surfaces, so a config flip has to be faster than a revert.
COHORT_DEPENDENCY_INCREMENTAL_MAINTENANCE: bool = get_from_env(
"COHORT_DEPENDENCY_INCREMENTAL_MAINTENANCE", True, type_cast=str_to_bool
)
9 changes: 9 additions & 0 deletions posthog/settings/data_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,14 @@ def _apply_product_db_ssl_options(db: str, options: dict) -> None:
"LOCATION": REDIS_URL,
}

# Cohort dependency reads must see the writes made earlier in the same request: the create path
# writes the new cohort's keys and then reads them back before responding, and a replica-lag miss
# there rescans every cohort of the team inside the request.
CACHES["cohort_dependencies"] = {
**CACHES["default"],
"LOCATION": REDIS_URL,
}

# Dedicated cache for the feature flags service (if configured)
# Django only writes to this cache (never reads), so no reader URL needed
if FLAGS_REDIS_URL:
Expand Down Expand Up @@ -749,6 +757,7 @@ def _apply_product_db_ssl_options(db: str, options: dict) -> None:
CACHES["default"] = {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}
CACHES["query_cache"] = CACHES["default"]
CACHES["organization_access"] = CACHES["default"]
CACHES["cohort_dependencies"] = CACHES["default"]

# Cache timeout for materialized columns metadata (in seconds)
MATERIALIZED_COLUMNS_CACHE_TIMEOUT: int = get_from_env("MATERIALIZED_COLUMNS_CACHE_TIMEOUT", 900, type_cast=int)
Expand Down
Loading
Loading