Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cancel queries on navigation-ish #13414

Merged
merged 19 commits into from Dec 29, 2022

Conversation

pauldambra
Copy link
Member

Problem

We have query cancellation that fires when someone changes filters while a slow query is running.

But, they may become frustrated and navigate away within the app. We would leave any ClickHouse queries running in that case.

Changes

Calls into the mounted dashboard or insight logic when the Dashboard.tsx or Insight.tsx is unmounted and attempts to cancel queries

NB: this doesn't try to unify this cancellation mechanism between insights and dashboards, just adds the new reasons to call it

How did you test this code?

running locally and 👀

@macobo
Copy link
Contributor

macobo commented Dec 20, 2022

Would be great to confirm in what navigation scenarios queries get cancelled now and in which they don't.


useEffect(() => {
reportDashboardViewed()
return () => {
Copy link
Contributor

@macobo macobo Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: create a useQueryCancellation(fn) wrapping useEffect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with wrapping (or at least the problem I've not figured out the solution to) is the insight and dashboard cancellation cases are still really different

@pauldambra
Copy link
Member Author

Would be great to confirm in what navigation scenarios queries get cancelled now and in which they don't.

So, we have the existing behaviour that catches changes in filters and cancels running queries.

This adds cancelling queries when the components are no longer in the DOM.

So the cases covered right now

  • when an insight is running and you navigate to another page
  • when an insight is running and you change anything that causes a new query to start
  • when a dashboard is running and you navigate to another page
  • when a dashboard is running and you change the time range or a filter

@@ -295,11 +296,14 @@ export const insightLogic = kea<insightLogicType>([
// fetch this now, as it might be different when we report below
const scene = sceneLogic.isMounted() ? sceneLogic.values.scene : null

// If a query is in progress, kill that query
if (cache.abortController) {
Copy link
Contributor

@macobo macobo Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we dispatch abortAnyRunningQuery here? Or extract function to keep DRY as we repeat the same code many times.

breakpoint()
cache.abortController = null

if (!cancelled && refreshesFinished === insights.length) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macobo one last thing to check now I have the tests passing

I've had to add a !cancelled gate here because sometimes this conditional was executed after tests had finished running.

I think it's OK not to report time_to_see data for the dashboard load here since we'd be reporting on the cancellation but....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up.

@pauldambra pauldambra merged commit 63e7fcd into master Dec 29, 2022
@pauldambra pauldambra deleted the feat/query-cancel-on-navigation-ish branch December 29, 2022 09:42
@pauldambra pauldambra added the highlight ⭐ Release highlight label Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
highlight ⭐ Release highlight
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants