From 9a3225e387d9bb5050a72475d95d3d16168f9035 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Feb 2020 02:31:34 -0800 Subject: [PATCH] file serve stats --- gun.js | 5 ++++- lib/radisk.js | 2 +- lib/serve.js | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gun.js b/gun.js index bbdf4074..96ed9530 100644 --- a/gun.js +++ b/gun.js @@ -711,6 +711,7 @@ if(!msg){ return } var ctx = msg._||'', root = ctx.root = ((msg.$||'')._||'').root; var put = msg.put, id = msg['#'], err, tmp; + var DBG = ctx.DBG = msg.DBG; if(put['#']){ root.on('put', msg); return } /*root.on(id, function(m){ console.log('ack:', m); @@ -733,6 +734,7 @@ } if(err){ break } } + DBG && (DBG.p = +new Date); if(console.STAT){ console.STAT(S, +new Date - S, 'mix');console.STAT(S, ctx.lot.s, 'mix #') } if(ctx.err = err){ root.on('in', {'@': id, err: Gun.log(err)}); return } if(!(--ctx.lot.more)){ fire(ctx) } // if synchronous. @@ -754,10 +756,11 @@ } (lot = ctx.lot||'').s++; lot.more++; (ctx.stun || (ctx.stun = {}))[soul+key] = 1; + var DBG = ctx.DBG; DBG && (DBG.ph = DBG.ph || +new Date); root.on('put', {'#': msg['#'], put: {'#': soul, '.': key, ':': val, '>': state}, _: ctx}); } function map(msg){ - (msg._||'').DBG && ((msg._||'').DBG.m = +new Date); + var DBG; if(DBG = (msg._||'').DBG){ DBG.pa = +new Date; DBG.pm = DBG.pm || +new Date} var eve = this, root = eve.as, graph = root.graph, ctx = msg._, put = msg.put, soul = put['#'], key = put['.'], val = put[':'], state = put['>'], id = msg['#'], tmp; graph[soul] = state_ify(graph[soul], key, state, val, soul); // TODO: Only put in graph if subscribed? Relays vs Browsers? chain(ctx, soul, key, (u !== (tmp = put['=']))? tmp : val, state); // TODO: This should NOT be how the API works, this should be done at an extension layer, but hacky solution to migrate with old code for now. diff --git a/lib/radisk.js b/lib/radisk.js index c1d6b9f4..cd8030c7 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -59,7 +59,7 @@ r.parse(file, s.mix); } s.mix = function(err, disk){ - if(s.err = err || s.err){ console.log("????", cb, "????"); cb(err); return } // TODO: HANDLE BATCH EMIT + if(s.err = err || s.err){ cb(err); return } // TODO: HANDLE BATCH EMIT var file = s.file = (disk||'').file || s.file, tmp; if(!disk && file !== opt.code.from){ // corrupt file? r.find.bad(file); // remove from dir list diff --git a/lib/serve.js b/lib/serve.js index 76dca3c4..2bc80c4f 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -32,8 +32,9 @@ function serve(req, res, next){ var tmp; fs.readdir(path, function(err, dir){ res.end((dir || (err && 404))+'') }); return true; } + var S = +new Date; var rs = fs.createReadStream(path); - rs.on('open', function(){ rs.pipe(res) }); + rs.on('open', function(){ console.STAT && console.STAT(S, +new Date - S, 'serve open file'); rs.pipe(res) }); rs.on('error', function(err){ res.end(404+'') }); return true; }