diff --git a/public/app/features/explore/ExploreToolbar.tsx b/public/app/features/explore/ExploreToolbar.tsx index dcc3a9f6c5b..a1787e81c7c 100644 --- a/public/app/features/explore/ExploreToolbar.tsx +++ b/public/app/features/explore/ExploreToolbar.tsx @@ -19,7 +19,7 @@ import { ExploreTimeControls } from './ExploreTimeControls'; import { LiveTailButton } from './LiveTailButton'; import { RunButton } from './RunButton'; import { LiveTailControls } from './useLiveTailControls'; -import { cancelQueries, clearQueries, runQueries, clearCache } from './state/query'; +import { cancelQueries, clearQueries, runQueries } from './state/query'; import ReturnToDashboardButton from './ReturnToDashboardButton'; import { isSplit } from './state/selectors'; @@ -40,12 +40,10 @@ export class UnConnectedExploreToolbar extends PureComponent { }; onRunQuery = (loading = false) => { - const { clearCache, runQueries, cancelQueries, exploreId } = this.props; + const { runQueries, cancelQueries, exploreId } = this.props; if (loading) { return cancelQueries(exploreId); } else { - // We want to give user a chance tu re-run the query even if it is saved in cache - clearCache(exploreId); return runQueries(exploreId); } }; @@ -249,7 +247,6 @@ const mapDispatchToProps = { split: splitOpen, syncTimes, onChangeTimeZone: updateTimeZoneForSession, - clearCache, }; const connector = connect(mapStateToProps, mapDispatchToProps); diff --git a/public/app/features/explore/state/query.ts b/public/app/features/explore/state/query.ts index 50dab0f612a..10fe7ee9b64 100644 --- a/public/app/features/explore/state/query.ts +++ b/public/app/features/explore/state/query.ts @@ -304,10 +304,19 @@ export function modifyQueries( /** * Main action to run queries and dispatches sub-actions based on which result viewers are active */ -export const runQueries = (exploreId: ExploreId, options?: { replaceUrl?: boolean }): ThunkResult => { +export const runQueries = ( + exploreId: ExploreId, + options?: { replaceUrl?: boolean; preserveCache?: boolean } +): ThunkResult => { return (dispatch, getState) => { dispatch(updateTime({ exploreId })); + // We always want to clear cache unless we explicitly pass preserveCache parameter + const preserveCache = options?.preserveCache === true; + if (!preserveCache) { + dispatch(clearCache(exploreId)); + } + const richHistory = getState().explore.richHistory; const exploreItemState = getState().explore[exploreId]!; const { diff --git a/public/app/features/explore/state/time.ts b/public/app/features/explore/state/time.ts index e3217008d90..8ae40394154 100644 --- a/public/app/features/explore/state/time.ts +++ b/public/app/features/explore/state/time.ts @@ -47,12 +47,14 @@ export const updateTimeRange = (options: { const { syncedTimes } = getState().explore; if (syncedTimes) { dispatch(updateTime({ ...options, exploreId: ExploreId.left })); - dispatch(runQueries(ExploreId.left)); + // When running query by updating time range, we want to preserve cache. + // Cached results are currently used in Logs pagination. + dispatch(runQueries(ExploreId.left, { preserveCache: true })); dispatch(updateTime({ ...options, exploreId: ExploreId.right })); - dispatch(runQueries(ExploreId.right)); + dispatch(runQueries(ExploreId.right, { preserveCache: true })); } else { dispatch(updateTime({ ...options })); - dispatch(runQueries(options.exploreId)); + dispatch(runQueries(options.exploreId, { preserveCache: true })); } }; };