mirror of
https://github.com/amark/gun.git
synced 2025-06-07 22:56:42 +00:00
fix open, warn if too fast
This commit is contained in:
parent
2ff35aa316
commit
5ea98f48e3
8
gun.js
8
gun.js
@ -306,7 +306,7 @@
|
|||||||
}
|
}
|
||||||
ctx.latch = root.hatch; ctx.match = root.hatch = [];
|
ctx.latch = root.hatch; ctx.match = root.hatch = [];
|
||||||
var put = msg.put;
|
var put = msg.put;
|
||||||
var DBG = ctx.DBG = msg.DBG, S = +new Date;
|
var DBG = ctx.DBG = msg.DBG, S = +new Date; CT = CT || S;
|
||||||
if(put['#'] && put['.']){ /*root && root.on('put', msg);*/ return } // TODO: BUG! This needs to call HAM instead.
|
if(put['#'] && put['.']){ /*root && root.on('put', msg);*/ return } // TODO: BUG! This needs to call HAM instead.
|
||||||
DBG && (DBG.p = S);
|
DBG && (DBG.p = S);
|
||||||
ctx['#'] = msg['#'];
|
ctx['#'] = msg['#'];
|
||||||
@ -343,6 +343,7 @@
|
|||||||
if(!valid(val)){ err = ERR+cut(key)+"on"+cut(soul)+"bad "+(typeof val)+cut(val); break }
|
if(!valid(val)){ err = ERR+cut(key)+"on"+cut(soul)+"bad "+(typeof val)+cut(val); break }
|
||||||
//ctx.all++; //ctx.ack[soul+key] = '';
|
//ctx.all++; //ctx.ack[soul+key] = '';
|
||||||
ham(val, key, soul, state, msg);
|
ham(val, key, soul, state, msg);
|
||||||
|
++C; // courtesy count;
|
||||||
}
|
}
|
||||||
if((kl = kl.slice(i)).length){ turn(pop); return }
|
if((kl = kl.slice(i)).length){ turn(pop); return }
|
||||||
++ni; kl = null; pop(o);
|
++ni; kl = null; pop(o);
|
||||||
@ -392,6 +393,8 @@
|
|||||||
if(!(msg = ctx.msg) || ctx.err || msg.err){ return }
|
if(!(msg = ctx.msg) || ctx.err || msg.err){ return }
|
||||||
msg.out = universe;
|
msg.out = universe;
|
||||||
ctx.root.on('out', msg);
|
ctx.root.on('out', msg);
|
||||||
|
|
||||||
|
CF(); // courtesy check;
|
||||||
}
|
}
|
||||||
function ack(msg){ // aggregate ACKs.
|
function ack(msg){ // aggregate ACKs.
|
||||||
var id = msg['@'] || '', ctx;
|
var id = msg['@'] || '', ctx;
|
||||||
@ -413,6 +416,7 @@
|
|||||||
var ERR = "Error: Invalid graph!";
|
var ERR = "Error: Invalid graph!";
|
||||||
var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " }
|
var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " }
|
||||||
var L = JSON.stringify, MD = 2147483647, State = Gun.state;
|
var L = JSON.stringify, MD = 2147483647, State = Gun.state;
|
||||||
|
var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}};
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@ -1339,7 +1343,7 @@
|
|||||||
var noop = function(){}
|
var noop = function(){}
|
||||||
var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
|
var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
|
||||||
var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
|
var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
|
||||||
json.sucks = function(d){ if(d > 99){ Gun.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } }
|
json.sucks = function(d){ if(d > 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } }
|
||||||
|
|
||||||
function Mesh(root){
|
function Mesh(root){
|
||||||
var mesh = function(){};
|
var mesh = function(){};
|
||||||
|
26
lib/open.js
26
lib/open.js
@ -1,7 +1,7 @@
|
|||||||
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
|
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
|
||||||
|
|
||||||
window.list = {};
|
Gun.chain.open = function(cb, opt, at, depth){ // this is a recursive function, BEWARE!
|
||||||
Gun.chain.open = function(cb, opt, at){ // this is a recursive function!
|
depth = depth || 1;
|
||||||
opt = opt || {}; // init top level options.
|
opt = opt || {}; // init top level options.
|
||||||
opt.doc = opt.doc || {};
|
opt.doc = opt.doc || {};
|
||||||
opt.ids = opt.ids || {};
|
opt.ids = opt.ids || {};
|
||||||
@ -13,11 +13,7 @@ Gun.chain.open = function(cb, opt, at){ // this is a recursive function!
|
|||||||
});
|
});
|
||||||
opt.eve.s = {};
|
opt.eve.s = {};
|
||||||
}, s:{}}
|
}, s:{}}
|
||||||
return this.on(function(data, key, ctx, eve){ // subscribe to 1 deeper layer of data!
|
return this.on(function(data, key, ctx, eve){ // subscribe to 1 deeper of data!
|
||||||
if(opt.meta !== true){
|
|
||||||
//delete data._; // This should be safe now?
|
|
||||||
delete ((data = JSON.parse(JSON.stringify(data||'')))||{})._; // BAD PERFORMANCE BUT TRY ANYWAYS!
|
|
||||||
}
|
|
||||||
clearTimeout(opt.to); // do not trigger callback if bunch of changes...
|
clearTimeout(opt.to); // do not trigger callback if bunch of changes...
|
||||||
opt.to = setTimeout(function(){ // but schedule the callback to fire soon!
|
opt.to = setTimeout(function(){ // but schedule the callback to fire soon!
|
||||||
if(!opt.any){ return }
|
if(!opt.any){ return }
|
||||||
@ -26,7 +22,7 @@ Gun.chain.open = function(cb, opt, at){ // this is a recursive function!
|
|||||||
opt.eve.off();
|
opt.eve.off();
|
||||||
opt.any = null;
|
opt.any = null;
|
||||||
}
|
}
|
||||||
}, opt.wait || 1);
|
}, opt.wait || 9);
|
||||||
opt.at = opt.at || ctx; // opt.at will always be the first context it finds.
|
opt.at = opt.at || ctx; // opt.at will always be the first context it finds.
|
||||||
opt.key = opt.key || key;
|
opt.key = opt.key || key;
|
||||||
opt.eve.s[this._.id] = eve; // collect all the events together.
|
opt.eve.s[this._.id] = eve; // collect all the events together.
|
||||||
@ -40,23 +36,23 @@ Gun.chain.open = function(cb, opt, at){ // this is a recursive function!
|
|||||||
}
|
}
|
||||||
var tmp = this; // else if a sub-object, CPU schedule loop over properties to do recursion.
|
var tmp = this; // else if a sub-object, CPU schedule loop over properties to do recursion.
|
||||||
setTimeout.each(Object.keys(data), function(key, val){
|
setTimeout.each(Object.keys(data), function(key, val){
|
||||||
|
if('_' === key && !opt.meta){ return }
|
||||||
val = data[key];
|
val = data[key];
|
||||||
var doc = at || opt.doc, id; // first pass this becomes the root of open, then at is passed below, and will be the parent for each sub-document/object.
|
var doc = at || opt.doc, id; // first pass this becomes the root of open, then at is passed below, and will be the parent for each sub-document/object.
|
||||||
if(!doc){ // if no "parent"
|
if(!doc){ return } // if no "parent"
|
||||||
return;
|
|
||||||
}
|
|
||||||
if('string' !== typeof (id = Gun.valid(val))){ // if primitive...
|
if('string' !== typeof (id = Gun.valid(val))){ // if primitive...
|
||||||
doc[key] = val;
|
doc[key] = val;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(opt.ids[id]){ // if we've already seen this sub-object/document
|
if(opt.ids[id]){ // if we've already seen this sub-object/document
|
||||||
list[id] = (list[id] || 0) + 1;
|
|
||||||
doc[key] = opt.ids[id]; // link to itself, our already in-memory one, not a new copy.
|
doc[key] = opt.ids[id]; // link to itself, our already in-memory one, not a new copy.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// now open up the recursion of sub-documents!
|
if(opt.depth <= depth){ // stop recursive open at max depth.
|
||||||
tmp.get(key).open(opt.any, opt, opt.ids[id] = doc[key] = {}); // 3rd param is now where we are "at".
|
doc[key] = doc[key] || val; // show link so app can load it if need.
|
||||||
|
return;
|
||||||
|
} // now open up the recursion of sub-documents!
|
||||||
|
tmp.get(key).open(opt.any, opt, opt.ids[id] = doc[key] = {}, depth+1); // 3rd param is now where we are "at".
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
GUN.C = 0;
|
|
Loading…
x
Reference in New Issue
Block a user