From a9e9c4c55b085b1b6743ca40f86c5836689b59bc Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 17 May 2017 14:22:02 -0700 Subject: [PATCH] [sql lab] fix user timestamp is off --- .../javascripts/SqlLab/components/QueryAutoRefresh.jsx | 2 +- superset/assets/javascripts/SqlLab/reducers.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/superset/assets/javascripts/SqlLab/components/QueryAutoRefresh.jsx b/superset/assets/javascripts/SqlLab/components/QueryAutoRefresh.jsx index 0f53c09e9c856..892b7caf5294f 100644 --- a/superset/assets/javascripts/SqlLab/components/QueryAutoRefresh.jsx +++ b/superset/assets/javascripts/SqlLab/components/QueryAutoRefresh.jsx @@ -36,7 +36,7 @@ class QueryAutoRefresh extends React.PureComponent { stopwatch() { // only poll /superset/queries/ if there are started or running queries if (this.shouldCheckForQueries()) { - const url = '/superset/queries/' + (this.props.queriesLastUpdate - QUERY_UPDATE_BUFFER_MS); + const url = `/superset/queries/${this.props.queriesLastUpdate - QUERY_UPDATE_BUFFER_MS}`; $.getJSON(url, (data) => { if (Object.keys(data).length > 0) { this.props.actions.refreshQueries(data); diff --git a/superset/assets/javascripts/SqlLab/reducers.js b/superset/assets/javascripts/SqlLab/reducers.js index 121809b6d6b34..4b721aecbaa84 100644 --- a/superset/assets/javascripts/SqlLab/reducers.js +++ b/superset/assets/javascripts/SqlLab/reducers.js @@ -233,11 +233,15 @@ export const sqlLabReducer = function (state, action) { let newQueries = Object.assign({}, state.queries); // Fetch the updates to the queries present in the store. let change = false; + let queriesLastUpdate = state.queriesLastUpdate; for (const id in action.alteredQueries) { const changedQuery = action.alteredQueries[id]; if (!state.queries.hasOwnProperty(id) || (state.queries[id].changedOn !== changedQuery.changedOn && state.queries[id].state !== 'stopped')) { + if (changedQuery.changedOn > queriesLastUpdate) { + queriesLastUpdate = changedQuery.changedOn; + } newQueries[id] = Object.assign({}, state.queries[id], changedQuery); change = true; } @@ -245,7 +249,6 @@ export const sqlLabReducer = function (state, action) { if (!change) { newQueries = state.queries; } - const queriesLastUpdate = now(); return Object.assign({}, state, { queries: newQueries, queriesLastUpdate }); }, };