Update gun.js

This commit is contained in:
Mark Nadal 2016-12-09 18:13:25 -08:00 committed by GitHub
parent c5f7b6283b
commit 69d1e81fc9

14
gun.js
View File

@ -1027,25 +1027,26 @@
return Gun.obj.has(this.cache, id);
}
Dedup.prototype.gc = function(){
var de = this;
var now = Gun.time.is();
var oldest = now;
var maxAge = 5 * 60 * 1000;
// TODO: Gun.scheduler already does this? Reuse that.
Gun.obj.map(this.cache, function (time, id) {
Gun.obj.map(de.cache, function (time, id) {
oldest = Math.min(now, time);
if ((now - time) < maxAge) {
return;
}
delete this.cache[id];
delete de.cache[id];
});
var done = Gun.obj.empty(this.cache);
var done = Gun.obj.empty(de.cache);
// Disengage GC.
if (done) {
this.to = null;
de.to = null;
return;
}
@ -1056,8 +1057,7 @@
var nextGC = maxAge - elapsed;
// Schedule the next GC event.
var dedup = this;
this.to = setTimeout(function(){ dedup.gc() }, nextGC);
de.to = setTimeout(function(){ de.gc() }, nextGC);
}
}());
var text = Type.text, text_is = text.is, text_random = text.random;
@ -2486,4 +2486,4 @@
})(require, './adapters/wsp');
}());
}());