Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(caching): warm insight cache as creator (#66649)

Alex Lider4bbea0e3a27a
diff --git a/posthog/caching/insight_cache.py b/posthog/caching/insight_cache.py
index b7080eeb4f80..5d3645b69ac0 100644
--- a/posthog/caching/insight_cache.py
+++ b/posthog/caching/insight_cache.py
@@ -84,6 +84,7 @@ def update_cache(caching_state_id: UUID):
cast(dict[str, Any], insight.query),
dashboard_filters_json=dashboard.filters if dashboard is not None else None,
execution_mode=ExecutionMode.CALCULATE_BLOCKING_ALWAYS,
+ user=insight.created_by,
analytics_props={"source": EventSource.CACHE_WARMING},
)
# TRICKY: `result` is null, because `process_query` already set the cache. `cache_type` also irrelevant
diff --git a/posthog/caching/warming.py b/posthog/caching/warming.py
index 2c2e08dd8fd5..1c647caf7e03 100644
--- a/posthog/caching/warming.py
+++ b/posthog/caching/warming.py
@@ -243,6 +243,7 @@ def warm_insight_cache_task(insight_id: int, dashboard_id: Optional[int]):
# - if insight + dashboard combinations have the same cache key, we prevent needless recalculations
limit_context=LimitContext.QUERY_ASYNC,
execution_mode=ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALE,
+ user=insight.created_by,
insight_id=insight_id,
dashboard_id=dashboard_id,
analytics_props={"source": EventSource.CACHE_WARMING},