posthog icon indicating copy to clipboard operation
posthog copied to clipboard

fix(insights): Adjust dashboard latest refresh logic

Open webjunkie opened this issue 1 year ago • 3 comments

Problem

Observation:

  • load dashboard with stale items, all get refreshed
  • if some tiles time out while refreshing, their latest_refresh will 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=True to 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?

  • 👀

webjunkie avatar Apr 29 '24 08:04 webjunkie

@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.

webjunkie avatar Apr 29 '24 08:04 webjunkie

Size Change: 0 B

Total Size: 1.04 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.04 MB

compressed-size-action

github-actions[bot] avatar Apr 29 '24 08:04 github-actions[bot]

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

Twixes avatar Apr 29 '24 14:04 Twixes