Skip to content

Commit

Permalink
help sqllab forget the past
Browse files Browse the repository at this point in the history
  • Loading branch information
timifasubaa committed Apr 18, 2018
1 parent eac97ce commit e47d8a5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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) => {
Expand Down

0 comments on commit e47d8a5

Please sign in to comment.