Change ghetto timer to debounce

This commit is contained in:
Pavel Djundik 2016-11-19 23:00:54 +02:00
parent 463a63aed3
commit 4fe3c5e96a

View File

@ -460,23 +460,13 @@ Client.prototype.clientDetach = function(socketId) {
delete this.attachedClients[socketId]; delete this.attachedClients[socketId];
}; };
var timer; Client.prototype.save = _.debounce(function SaveClient() {
Client.prototype.save = function(force) {
var client = this;
if (Helper.config.public) { if (Helper.config.public) {
return; return;
} }
if (!force) { const client = this;
clearTimeout(timer); let json = {};
timer = setTimeout(function() {
client.save(true);
}, 1000);
return;
}
var json = {};
json.networks = this.networks.map(n => n.export()); json.networks = this.networks.map(n => n.export());
client.manager.updateUser(client.name, json); client.manager.updateUser(client.name, json);
}; }, 1000, {maxWait: 10000});