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

12
gun.js
View File

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