From 081f954a2b538edd6af56d42dba1b580f71a191e Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 Jul 2020 15:04:57 +0200 Subject: [PATCH] Explore: Don't run queries on datasource change (#26033) - more and more datasources are having long-running queries, automatically triggering is becoming more of a burden than a help. - some datasource queries might actually cost money, so running queries should be explicit. --- public/app/features/explore/state/actions.test.ts | 4 +++- public/app/features/explore/state/actions.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/public/app/features/explore/state/actions.test.ts b/public/app/features/explore/state/actions.test.ts index 492be9b5d42..c8c8d6b1750 100644 --- a/public/app/features/explore/state/actions.test.ts +++ b/public/app/features/explore/state/actions.test.ts @@ -259,7 +259,7 @@ describe('changing datasource', () => { jest.spyOn(Actions, 'importQueries').mockImplementationOnce(() => jest.fn); jest.spyOn(Actions, 'loadDatasource').mockImplementationOnce(() => jest.fn); - jest.spyOn(Actions, 'runQueries').mockImplementationOnce(() => jest.fn); + const runQueriesAction = jest.spyOn(Actions, 'runQueries').mockImplementationOnce(() => jest.fn); const dispatchedActions = await thunkTester(initialState) .givenThunk(changeDatasource) .whenThunkIsDispatched(exploreId, name); @@ -272,6 +272,8 @@ describe('changing datasource', () => { mode: ExploreMode.Logs, }), ]); + // Don't run queries just on datasource change + expect(runQueriesAction).toHaveBeenCalledTimes(0); }); }); diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index 809d507a657..b4db347e723 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -157,7 +157,6 @@ export function changeDatasource(exploreId: ExploreId, datasourceName: string): } await dispatch(loadDatasource(exploreId, newDataSourceInstance, orgId)); - dispatch(runQueries(exploreId)); }; } @@ -265,11 +264,12 @@ export function loadExploreDatasourcesAndSetDatasource( exploreId: ExploreId, datasourceName: string ): ThunkResult { - return dispatch => { + return async dispatch => { const exploreDatasources = getExploreDatasources(); if (exploreDatasources.length >= 1) { - dispatch(changeDatasource(exploreId, datasourceName)); + await dispatch(changeDatasource(exploreId, datasourceName)); + dispatch(runQueries(exploreId)); } else { dispatch(loadDatasourceMissingAction({ exploreId })); }