Skip to content

Commit

Permalink
feat(insights): Make initial single insight load async (#23808)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Matloka <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent 6da45c8 commit 75ec240
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 7 deletions.
6 changes: 4 additions & 2 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,16 @@ const api = {
insights: {
loadInsight(
shortId: InsightModel['short_id'],
basic?: boolean
basic?: boolean,
refresh?: RefreshType
): Promise<PaginatedResponse<Partial<InsightModel>>> {
return new ApiRequest()
.insights()
.withQueryString(
toParams({
short_id: encodeURIComponent(shortId),
basic: basic,
basic,
refresh,
})
)
.get()
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
if (oldProps.query?.kind && props.query.kind !== oldProps.query.kind) {
actions.clearResponse()
}
if (
const queryStatus = (props.cachedResults?.query_status || null) as QueryStatus | null
if (queryStatus?.complete === false) {
// If there is an incomplete query, load the data with the same query_id which should return its status
actions.loadData(undefined, queryStatus.id)
} else if (
!(props.cachedResults && props.key.includes('dashboard')) && // Don't load data on dashboard if cached results are available
!queryEqual(props.query, oldProps.query) &&
(!props.cachedResults ||
Expand All @@ -141,7 +145,7 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
}
}),
actions({
loadData: (refresh = false) => ({ refresh, queryId: uuid() }),
loadData: (refresh = false, queryId?: string) => ({ refresh, queryId: queryId || uuid() }),
abortAnyRunningQuery: true,
abortQuery: (payload: { queryId: string }) => payload,
cancelQuery: true,
Expand All @@ -166,7 +170,8 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
return props.cachedResults
}

if (props.cachedResults && !refresh) {
const queryStatus = (props.cachedResults?.query_status || null) as QueryStatus | null
if (props.cachedResults && !refresh && queryStatus?.complete !== false) {
if (props.cachedResults['result'] || props.cachedResults['results']) {
return props.cachedResults
}
Expand Down
Loading

0 comments on commit 75ec240

Please sign in to comment.