From 13c13c71f9542f2968638d157e3e248abdee5393 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 5 Jul 2021 14:49:51 -0700 Subject: [PATCH] what on earth happened to my browser/OS? "unplug & plug it back in" restart seemed to fix it. --- gun.js | 22 ++++++++++++++++++---- test/common.js | 19 ++++++++++++------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/gun.js b/gun.js index 9c7dca0d..bc3919e5 100644 --- a/gun.js +++ b/gun.js @@ -417,6 +417,20 @@ var next = root.next || (root.next = {}), at = next[soul]; // queue concurrent GETs? // TODO: consider tagging original message into dup for DAM. + // TODO: ^ above? In chat app, 12 messages resulted in same peer asking for `#user.pub` 12 times. (same with #user GET too, yipes!) // DAM note: This also resulted in 12 replies from 1 peer which all had same ##hash but none of them deduped because each get was different. + // TODO: localStorage reply did not get chunked. + // TMP note for now: viMZq1slG was chat LEX query #. + /*if(gun !== (tmp = msg.$) && (tmp = (tmp||'')._)){ + if(tmp.Q){ return } // chain does not need to ask for it again. + tmp.Q = {}; + }*/ + /*if(u === has){ + if(at.Q){ + //at.Q[msg['#']] = ''; + //return; + } + at.Q = {}; + }*/ var ctx = msg._||{}, DBG = ctx.DBG = msg.DBG; DBG && (DBG.g = +new Date); //console.log("GET:", get, node, has); @@ -1027,7 +1041,7 @@ } setTimeout.each(Object.keys(stun), function(cb){ if(cb = stun[cb]){cb()} }); // resume the stunned reads // Any perf reasons to CPU schedule this .keys( ? }).hatch = tmp; // this is not official yet ^ - //console.only(1, "PUT", as.run, as.graph); + //console.log(1, "PUT", as.run, as.graph); (as.via._).on('out', {put: as.out = as.graph, opt: as.opt, '#': ask, _: tmp}); } @@ -1131,11 +1145,11 @@ if('string' == typeof tmp){ return } // TODO: BUG? Will this always load? clearTimeout(one[id]); one[id] = setTimeout(once, opt.wait||99); // TODO: Bug? This doesn't handle plural chains. function once(){ - if(eve.stun){ return } if('' === one[id]){ return } one[id] = ''; - if(cat.soul || cat.has){ eve.off() } // TODO: Plural chains? // else { ?.off() } // better than one check? if(!at.has && !at.soul){ at = {put: data, get: key} } // handles non-core messages. if(u === (tmp = at.put)){ tmp = ((msg.$$||'')._||'').put } - if('string' == typeof Gun.valid(tmp)){ tmp = root.$.get(tmp)._.put; if(tmp === u){return} } // TODO: Can we delete this line of code, because the line below (which was inspired by @rogowski) handles it anyways? + if('string' == typeof Gun.valid(tmp)){ tmp = root.$.get(tmp)._.put; if(tmp === u){return} } + if(eve.stun){ return } if('' === one[id]){ return } one[id] = ''; + if(cat.soul || cat.has){ eve.off() } // TODO: Plural chains? // else { ?.off() } // better than one check? cb.call($, tmp, at.get); }; }, {on: 1}); diff --git a/test/common.js b/test/common.js index b8b839db..dd7dfe4a 100644 --- a/test/common.js +++ b/test/common.js @@ -7,7 +7,6 @@ describe('Gun', function(){ root = env.window? env.window : global; try{ env.window && root.localStorage && root.localStorage.clear() }catch(e){} try{ localStorage.clear() }catch(e){} - try{ indexedDB.deleteDatabase('radatatest') }catch(e){} try{ require('fs').unlinkSync('data.json') }catch(e){} try{ require('../lib/fsrm')('radatatest') }catch(e){} //root.Gun = root.Gun || require('../gun'); @@ -18,10 +17,8 @@ describe('Gun', function(){ require('../lib/yson'); root.Gun = require('../gun'); root.Gun.TESTING = true; - Gun.serve = require('../lib/serve'); - //require('../lib/file'); - require('../lib/store'); - require('../lib/rfs'); + require('../lib/store'); + require('../lib/rfs'); console.log("UNDO THIS SO RAD & SEA RUN!"); //require('./rad/rad.js'); //require('./sea/sea.js'); @@ -40,6 +37,14 @@ describe('Gun', function(){ var t = {}; describe('Utility', function(){ + it('deleting old GUN tests (may take long time)', function(done){ + done(); // Mocha doesn't print test until after its done, so show this first. + }); + it('deleted', function(done){ + this.timeout(60 * 1000); + if(!Gun.window){ return done() } + indexedDB.deleteDatabase('radatatest').onsuccess = function(e){ done() } + }); var u; /* // causes logger to no longer log. it('verbose console.log debugging', function(done) { @@ -3718,7 +3723,7 @@ describe('Gun', function(){ // TODO: It would be nice if we could change these numbers for different platforms/versions of javascript interpreters so we can squeeze as much out of them. gun.get('history').map().on(function(time, index){ diff = +new Date - time; - //console.log(">>>", index, time, diff);return; + //console.log(">>>", index, time, diff);//return; expect(gone[index]).to.not.be.ok(); gone[index] = diff; largest = (largest < diff)? diff : largest; @@ -8231,4 +8236,4 @@ describe('Gun', function(){ }, 100); }); }); -}); +}); \ No newline at end of file