From e47d8a59a4773f29e62d9b33d7ad6ad2b343abdd Mon Sep 17 00:00:00 2001 From: Timi Fasubaa Date: Mon, 16 Apr 2018 12:57:57 -0700 Subject: [PATCH] help sqllab forget the past --- .../assets/src/SqlLab/components/QueryAutoRefresh.jsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx b/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx index 892b7caf5294f..e026575fbda7b 100644 --- a/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx +++ b/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx @@ -8,6 +8,7 @@ const $ = require('jquery'); const QUERY_UPDATE_FREQ = 2000; const QUERY_UPDATE_BUFFER_MS = 5000; +const QUERY_POLL_WINDOW = 21600000; // 6 hours. class QueryAutoRefresh extends React.PureComponent { componentWillMount() { @@ -17,11 +18,11 @@ class QueryAutoRefresh extends React.PureComponent { this.stopTimer(); } shouldCheckForQueries() { - // if there are started or running queries, this method should return true + // if there are started or running queries < 6 hours old, this method should return true const { queries } = this.props; - const queryKeys = Object.keys(queries); - const queriesAsArray = queryKeys.map(key => queries[key]); - return queriesAsArray.some(q => + return Object.values(queries) + .filter(q => (q.startDttm >= this.props.queriesLastUpdate - QUERY_POLL_WINDOW)) + .some(q => ['running', 'started', 'pending', 'fetching'].indexOf(q.state) >= 0); } startTimer() { @@ -34,7 +35,7 @@ class QueryAutoRefresh extends React.PureComponent { this.timer = null; } stopwatch() { - // only poll /superset/queries/ if there are started or running queries + // only poll /superset/queries/ if there are started or running queries started <6 hours ago if (this.shouldCheckForQueries()) { const url = `/superset/queries/${this.props.queriesLastUpdate - QUERY_UPDATE_BUFFER_MS}`; $.getJSON(url, (data) => {