From cccbf02be5943aebc4fc0065933dcf7cf31be20b Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 29 Jan 2015 14:40:49 +0100 Subject: [PATCH] Make time to refresh "configurable", and limit refresh on focus Closes #7611 and jupyter/jupyter-drive#61 --- IPython/html/static/tree/js/main.js | 39 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 659b50ddc..2bdb089aa 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -82,26 +82,39 @@ require([ var interval_id=0; // auto refresh every xx secondes, no need to be fast, - // update is done at least when page get focus - var time_refresh = 60; // in sec + // update is done most of the time when page get focus + IPython.tree_time_refresh = 60; // in sec - var enable_autorefresh = function(){ - /** - *refresh immediately , then start interval - */ + // limit refresh on focus at 1/10sec, otherwise this + // can cause too frequent refresh on switching through windows or tabs. + IPython.min_delta_refresh = 10; // in sec + + var _last_refresh = null; + + var _refresh_list = function(){ + _last_refresh = new Date(); session_list.load_sessions(); cluster_list.load_list(); if (terminal_list) { terminal_list.load_terminals(); } + } + + var enable_autorefresh = function(){ + /** + *refresh immediately , then start interval + */ + var now = new Date() + + if (now - _last_refresh < IPython.min_delta_refresh*1000){ + console.log("Reenabling autorefresh too close to last tree refresh, not refreshing immediately again.") + } else { + _refresh_list(); + } if (!interval_id){ - interval_id = setInterval(function(){ - session_list.load_sessions(); - cluster_list.load_list(); - if (terminal_list) { - terminal_list.load_terminals(); - } - }, time_refresh*1000); + interval_id = setInterval(_refresh_list, + IPython.tree_time_refresh*1000 + ); } };