Skip to content

Commit

Permalink
chore(queryCache): remove dashboard queryCache from the UI (influxdat…
Browse files Browse the repository at this point in the history
  • Loading branch information
asalem1 authored Oct 6, 2020
1 parent b9cfb7c commit 6c0d860
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 41 deletions.
9 changes: 2 additions & 7 deletions src/dashboards/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
// Utils
import {event} from 'src/cloud/utils/reporting'
import {resetQueryCache} from 'src/shared/apis/queryCache'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'

// Selectors
import {getTimeRange} from 'src/dashboards/selectors'
Expand Down Expand Up @@ -106,9 +105,7 @@ const DashboardHeader: FC<Props> = ({
}

const handleChooseTimeRange = (timeRange: TimeRange) => {
if (isFlagEnabled('queryCacheForDashboards')) {
resetQueryCache()
}
resetQueryCache()
setDashboardTimeRange(dashboard.id, timeRange)
updateQueryParams({
lower: timeRange.lower,
Expand All @@ -132,9 +129,7 @@ const DashboardHeader: FC<Props> = ({

const resetCacheAndRefresh = (): void => {
// We want to invalidate the existing cache when a user manually refreshes the dashboard
if (isFlagEnabled('queryCacheForDashboards')) {
resetQueryCache()
}
resetQueryCache()
onManualRefresh()
}

Expand Down
9 changes: 2 additions & 7 deletions src/dashboards/components/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {AddNoteOverlay, EditNoteOverlay} from 'src/overlays/components'
import {pageTitleSuffixer} from 'src/shared/utils/pageTitles'
import {event} from 'src/cloud/utils/reporting'
import {resetQueryCache} from 'src/shared/apis/queryCache'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'

// Selectors
import {getByID} from 'src/resources/selectors'
Expand Down Expand Up @@ -49,17 +48,13 @@ const dashRoute = `/${ORGS}/${ORG_ID}/${DASHBOARDS}/${DASHBOARD_ID}`
@ErrorHandling
class DashboardPage extends Component<Props> {
public componentDidMount() {
if (isFlagEnabled('queryCacheForDashboards')) {
resetQueryCache()
}
resetQueryCache()

this.emitRenderCycleEvent()
}

public componentWillUnmount() {
if (isFlagEnabled('queryCacheForDashboards')) {
resetQueryCache()
}
resetQueryCache()
}

public render() {
Expand Down
5 changes: 1 addition & 4 deletions src/shared/components/TimeSeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ class TimeSeries extends Component<Props, State> {
const windowVars = getWindowVars(text, vars)
const extern = buildVarsOption([...vars, ...windowVars])
event('runQuery', {context: 'TimeSeries'})
if (
isCurrentPageDashboard &&
isFlagEnabled('queryCacheForDashboards')
) {
if (isCurrentPageDashboard) {
return onGetCachedResultsThunk(orgID, text)
}
const queryID = hashCode(text)
Expand Down
5 changes: 1 addition & 4 deletions src/timeMachine/actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ export const executeQueries = (abortController?: AbortController) => async (
const extern = buildVarsOption(variableAssignments)

event('runQuery', {context: 'timeMachine'})
if (
isCurrentPageDashboard(state) &&
isFlagEnabled('queryCacheForDashboards')
) {
if (isCurrentPageDashboard(state)) {
// reset any existing matching query in the cache
resetQueryCacheByQuery(text)
return getCachedResultsOrRunQuery(orgID, text, state)
Expand Down
35 changes: 16 additions & 19 deletions src/views/actions/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Libraries
import {normalize} from 'normalizr'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'

// APIs
import {
Expand Down Expand Up @@ -127,24 +126,22 @@ export const getViewAndResultsForVEO = (
})
)

if (isFlagEnabled('queryCacheForDashboards')) {
const queries = view.properties.queries.filter(({text}) => !!text.trim())
if (!queries.length) {
dispatch(setQueryResults(RemoteDataState.Done, [], null))
}
const {id: orgID} = getOrg(state)
const pendingResults = queries.map(({text}) => {
return getCachedResultsOrRunQuery(orgID, text, state)
})

// Wait for new queries to complete
const results = await Promise.all(pendingResults.map(r => r.promise))
const files = (results as RunQuerySuccessResult[]).map(r => r.csv)

if (files) {
dispatch(setQueryResults(RemoteDataState.Done, files, null, null))
return
}
const queries = view.properties.queries.filter(({text}) => !!text.trim())
if (!queries.length) {
dispatch(setQueryResults(RemoteDataState.Done, [], null))
}
const {id: orgID} = getOrg(state)
const pendingResults = queries.map(({text}) => {
return getCachedResultsOrRunQuery(orgID, text, state)
})

// Wait for new queries to complete
const results = await Promise.all(pendingResults.map(r => r.promise))
const files = (results as RunQuerySuccessResult[]).map(r => r.csv)

if (files) {
dispatch(setQueryResults(RemoteDataState.Done, files, null, null))
return
}

dispatch(executeQueries())
Expand Down

0 comments on commit 6c0d860

Please sign in to comment.