Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 7ff3f22

Browse files
committed
Slowly decrease polling frequency when tasklist is empty
1 parent f0a3963 commit 7ff3f22

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

core/src/plugins/core.tasks/js/react/PydioTasks.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@
145145

146146
constructor(){
147147
super();
148+
this._crtPoll = 10;
149+
150+
this._quickPoll = 2;
151+
this._longPoll = 15;
152+
this._pollSteps = 1.4;
148153
// Start listening to server messages
149154
global.pydio.observe("server_message", function(xml){
150155
var task = XMLUtils.XPathSelectSingleNode(xml, 'tree/task');
@@ -169,12 +174,7 @@
169174
taskMap.set(task.getId(), task);
170175
});
171176
this._tasksList = taskMap;
172-
this.notify("tasks_updated");
173-
if(tasks.length){
174-
global.pydio.notify("poller.frequency", {value:2});
175-
}else{
176-
global.pydio.notify("poller.frequency", {});
177-
}
177+
this.notifyAndSetPollerSpeed(tasks);
178178
}
179179
}
180180
}.bind(this));
@@ -193,12 +193,7 @@
193193
let taskMap = new Map();
194194
tasks.map(function(t){taskMap.set(t.getId(), t)});
195195
this._tasksList = taskMap;
196-
this.notify("tasks_updated");
197-
if(tasks.length){
198-
global.pydio.notify("poller.frequency", {value:2});
199-
}else{
200-
global.pydio.notify("poller.frequency", {});
201-
}
196+
this.notifyAndSetPollerSpeed(tasks);
202197
}.bind(this));
203198
}
204199
// Add local tasks
@@ -210,6 +205,21 @@
210205
return this._tasksList;
211206
}
212207

208+
notifyAndSetPollerSpeed(tasks){
209+
this.notify("tasks_updated");
210+
if(tasks.length){
211+
this._crtPoll = this._quickPoll;
212+
global.pydio.notify("poller.frequency", {value:this._quickPoll});
213+
}else{
214+
this._crtPoll *= this._pollSteps;
215+
if(this._crtPoll >= this._longPoll){
216+
global.pydio.notify("poller.frequency", {});
217+
}else{
218+
global.pydio.notify("poller.frequency", {value:this._crtPoll});
219+
}
220+
}
221+
}
222+
213223
enqueueLocalTask(task){
214224
if(!this._localTasks) {
215225
this._localTasks = new Map();

0 commit comments

Comments
 (0)