fix(insights): Adjust dashboard latest refresh logic
Problem
Observation:
- load dashboard with stale items, all get refreshed
- if some tiles time out while refreshing, their
latest_refreshwill stay a e.g. 3 days in the past - upon reload, the logic will see dashboard refresh is 3 days ago and reload all tiles
- we send
refresh=Trueto the /insight endpoint which recalculates even if stale (other choice would be never-recalculate)
Changes
- display actually latest refresh date (not oldest) in the dashboard reload button - I think this conveys it better to the users
- still use oldest to determine if a general refresh is needed
- when refreshing all, filter out those that are fresh within the last minutes already
Does this work well for both Cloud and self-hosted?
n/a
How did you test this code?
- 👀
@Twixes I think these date fixes here are generally a good idea, but we can also improve the requests still. I was wondering here
https://github.com/PostHog/posthog/blob/304540f0ce8acab330b6784e7e8f88934188c91b/posthog/caching/calculate_results.py#L122-L127
Why do we have always calculate or never? When the dashboard refreshes items and the requests get into here, we might still want the cache unless stale. Seems almost as if we need more than just boolean for refresh also in the endpoint.
Size Change: 0 B
Total Size: 1.04 MB
ℹ️ View Unchanged
| Filename | Size |
|---|---|
frontend/dist/toolbar.js |
1.04 MB |
Why do we have always calculate or never?
@webjunkie It's just how QueryRunners have been implemented since the beginning. I agree that what's now CALCULATION_ALWAYS should in fact return cached results if there are very recent ones. We have this in the legacy system, but it hasn't made it into the new one: https://github.com/PostHog/posthog/blob/60b03b7cdd949cba90d21f8aa345a1f3445d98fa/posthog/caching/insights_api.py#L55-L61