From d3b048085dc72f0230296682ca3a9becdd5c17da Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Sat, 23 Mar 2019 18:07:07 -0700 Subject: [PATCH] rindex 1M !!! --- gun.js | 32 ++++++++++++++------------------ test/rad/browser.html | 6 +++--- test/tmp/contacts.html | 5 ++++- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/gun.js b/gun.js index 6ff0faef..d7570667 100644 --- a/gun.js +++ b/gun.js @@ -1360,22 +1360,18 @@ // #soul.has=value>state // ~who#where.where=what>when@was // TODO: BUG! Put probably cannot handle plural chains! - var gun = this, at = (gun._), root = at.root.$, ctx = root._, tmp; - /*if(tmp = ctx.puts){ - if(tmp > 100){ // without this, when synchronous, writes to a 'not found' pile up, when 'not found' resolves it recursively calls `put` which incrementally resolves each write. Stack overflow limits can be as low as 10K, so this limit is hardcoded to 1% of 10K. - (ctx.stack || (ctx.stack = [])).push([gun, data, cb, as]); - clearTimeout(ctx.puto); - ctx.puto = setTimeout(function(){ - var stack = ctx.stack, i = 0, tmp; - ctx.stack = ctx.puts = ctx.puto = null; - while(tmp = stack[i++]){ - tmp[0].put(tmp[1], tmp[2], tmp[3]); - } - }, ctx.opt.wait || 1); - return gun; - } - ++ctx.puts; - } else { ctx.puts = 1 }*/ + var gun = this, at = (gun._), root = at.root.$, ctx = root._, M = 100, tmp; + if(!ctx.puta){ if(tmp = ctx.puts){ if(tmp > M){ // without this, when synchronous, writes to a 'not found' pile up, when 'not found' resolves it recursively calls `put` which incrementally resolves each write. Stack overflow limits can be as low as 10K, so this limit is hardcoded to 1% of 10K. + (ctx.stack || (ctx.stack = [])).push([gun, data, cb, as]); + if(ctx.puto){ return } + ctx.puto = setTimeout(function drain(){ + var d = ctx.stack.splice(0,M), i = 0, at; ctx.puta = true; + while(at = d[i++]){ at[0].put(at[1], at[2], at[3]) } delete ctx.puta; + if(ctx.stack.length){ return ctx.puto = setTimeout(drain, 0) } + ctx.stack = ctx.puts = ctx.puto = null; + }, 0); + return gun; + } ++ctx.puts } else { ctx.puts = 1 } } as = as || {}; as.data = data; as.via = as.$ = as.via || as.$ || gun; @@ -1470,7 +1466,7 @@ if(!ack.lack){ this.off() } // One response is good enough for us currently. Later we may want to adjust this. if(!as.ack){ return } as.ack(ack, this); - // --C; + //--C; }, as.opt); //C++; // NOW is a hack to get synchronous replies to correctly call. @@ -1487,7 +1483,7 @@ }, as); if(as.res){ as.res() } } function no(v,k){ if(v){ return true } } - //console.debug(999,1); var C = 0; setInterval(function(){ try{ debugg.innerHTML = C }catch(e){console.log(e)} }, 500); + //console.debug(999,1); var C = 0; setInterval(function(){ try{ debug.innerHTML = C }catch(e){console.log(e)} }, 500); function map(v,k,n, at){ var as = this; var is = Gun.is(v); diff --git a/test/rad/browser.html b/test/rad/browser.html index b8e6ccf1..d864fa0e 100644 --- a/test/rad/browser.html +++ b/test/rad/browser.html @@ -13,8 +13,8 @@ +
-
diff --git a/test/tmp/contacts.html b/test/tmp/contacts.html index 83044b95..f0d62502 100644 --- a/test/tmp/contacts.html +++ b/test/tmp/contacts.html @@ -14,8 +14,10 @@ +