Permalink
Browse files

Slowly decrease polling frequency when tasklist is empty

  • Loading branch information...
1 parent f0a3963 commit 7ff3f2233f6e89c38b63095ce7ddc69332082c5c @cdujeu cdujeu committed Sep 26, 2016
Showing with 22 additions and 12 deletions.
  1. +22 −12 core/src/plugins/core.tasks/js/react/PydioTasks.js
@@ -145,6 +145,11 @@
constructor(){
super();
+ this._crtPoll = 10;
+
+ this._quickPoll = 2;
+ this._longPoll = 15;
+ this._pollSteps = 1.4;
// Start listening to server messages
global.pydio.observe("server_message", function(xml){
var task = XMLUtils.XPathSelectSingleNode(xml, 'tree/task');
@@ -169,12 +174,7 @@
taskMap.set(task.getId(), task);
});
this._tasksList = taskMap;
- this.notify("tasks_updated");
- if(tasks.length){
- global.pydio.notify("poller.frequency", {value:2});
- }else{
- global.pydio.notify("poller.frequency", {});
- }
+ this.notifyAndSetPollerSpeed(tasks);
}
}
}.bind(this));
@@ -193,12 +193,7 @@
let taskMap = new Map();
tasks.map(function(t){taskMap.set(t.getId(), t)});
this._tasksList = taskMap;
- this.notify("tasks_updated");
- if(tasks.length){
- global.pydio.notify("poller.frequency", {value:2});
- }else{
- global.pydio.notify("poller.frequency", {});
- }
+ this.notifyAndSetPollerSpeed(tasks);
}.bind(this));
}
// Add local tasks
@@ -210,6 +205,21 @@
return this._tasksList;
}
+ notifyAndSetPollerSpeed(tasks){
+ this.notify("tasks_updated");
+ if(tasks.length){
+ this._crtPoll = this._quickPoll;
+ global.pydio.notify("poller.frequency", {value:this._quickPoll});
+ }else{
+ this._crtPoll *= this._pollSteps;
+ if(this._crtPoll >= this._longPoll){
+ global.pydio.notify("poller.frequency", {});
+ }else{
+ global.pydio.notify("poller.frequency", {value:this._crtPoll});
+ }
+ }
+ }
+
enqueueLocalTask(task){
if(!this._localTasks) {
this._localTasks = new Map();

0 comments on commit 7ff3f22

Please sign in to comment.