-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8ecb703
feat: cancel queries on navigation-ish
pauldambra 7ae4f46
request cancellation of insight query on any change to the insight
pauldambra 6ad60b3
cancel on navigation away and whenever a new query is started
pauldambra 5d44ab0
load insight if it is mounting in an error state
pauldambra fe2c3a5
Add comment
pauldambra e480015
dry it up a little
pauldambra 4989b1a
Merge branch 'master' into feat/query-cancel-on-navigation-ish
pauldambra 1064aba
clarify a comment
pauldambra b3c5e2f
Merge branch 'master' into feat/query-cancel-on-navigation-ish
pauldambra 09234ce
completely disable query cancellation to see if that is impacting pla…
pauldambra 22c6fc6
Revert "completely disable query cancellation to see if that is impac…
pauldambra 139a446
feat: test query cancellation (#13459)
pauldambra e4d2a70
remove feature flag
pauldambra 63c8259
Merge branch 'master' into feat/query-cancel-on-navigation-ish
pauldambra 3950a5c
Merge branch 'master' into feat/query-cancel-on-navigation-ish
pauldambra f971799
resolve post merge errors
pauldambra 4328195
correct posthog init
pauldambra c71bf97
fix test
pauldambra 706f9d8
don't report time to see as if complete for cancelled dashboards
pauldambra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,7 @@ export const insightLogic = kea<insightLogicType>([ | |
toggleVisibility: (index: number) => ({ index }), | ||
setHiddenById: (entry: Record<string, boolean | undefined>) => ({ entry }), | ||
highlightSeries: (seriesIndex: number | null) => ({ seriesIndex }), | ||
abortAnyRunningQuery: true, | ||
}), | ||
loaders(({ actions, cache, values, props }) => ({ | ||
insight: [ | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
cache.abortController.abort() | ||
cache.abortController = null | ||
} | ||
cache.abortController = new AbortController() | ||
const methodOptions: ApiMethodOptions = { | ||
signal: cache.abortController.signal, | ||
} | ||
|
||
const { filters } = values | ||
|
||
|
@@ -316,9 +320,6 @@ export const insightLogic = kea<insightLogicType>([ | |
let apiUrl: string = '' | ||
const { currentTeamId } = values | ||
|
||
const methodOptions: ApiMethodOptions = { | ||
signal: cache.abortController.signal, | ||
} | ||
if (!currentTeamId) { | ||
throw new Error("Can't load insight before current project is determined.") | ||
} | ||
|
@@ -749,7 +750,7 @@ export const insightLogic = kea<insightLogicType>([ | |
}, | ||
], | ||
}), | ||
listeners(({ actions, selectors, values }) => ({ | ||
listeners(({ actions, selectors, values, cache }) => ({ | ||
setFiltersMerge: ({ filters }) => { | ||
actions.setFilters({ ...values.filters, ...filters }) | ||
}, | ||
|
@@ -862,6 +863,12 @@ export const insightLogic = kea<insightLogicType>([ | |
) | ||
actions.setIsLoading(true) | ||
}, | ||
abortAnyRunningQuery: () => { | ||
if (cache.abortController) { | ||
cache.abortController.abort() | ||
cache.abortController = null | ||
} | ||
}, | ||
abortQuery: async ({ queryId }) => { | ||
const { currentTeamId } = values | ||
|
||
|
@@ -1055,7 +1062,7 @@ export const insightLogic = kea<insightLogicType>([ | |
} | ||
}, | ||
})), | ||
events(({ props, cache, values, actions }) => ({ | ||
events(({ props, values, actions }) => ({ | ||
afterMount: () => { | ||
if (!props.cachedInsight || !props.cachedInsight?.result || !!props.cachedInsight?.filters) { | ||
if ( | ||
|
@@ -1088,7 +1095,6 @@ export const insightLogic = kea<insightLogicType>([ | |
} | ||
}, | ||
beforeUnmount: () => { | ||
cache.abortController?.abort() | ||
if (values.timeout) { | ||
clearTimeout(values.timeout) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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