diff --git a/lib/radisk.js b/lib/radisk.js
index 8a5ff699..2ba43142 100644
--- a/lib/radisk.js
+++ b/lib/radisk.js
@@ -44,7 +44,6 @@
return cb(u, val);
}
}
- //console.log("READ FROM DISK");
return r.read(key, cb);
}
r.batch(key, val);
@@ -71,7 +70,7 @@
r.batch.ed = 0;
r.save(batch, function(err, ok){
if(++i > 1){ return }
- if(err){ Gun.log(err) }
+ if(err){ Gun.log('err', err) }
Gun.obj.map(batch.acks, function(cb){ cb(err, ok) });
thrash.at = null;
thrash.ing = false;
@@ -139,7 +138,7 @@
f.each = function(val, key, k, pre){
f.count++;
var enc = Radisk.encode(pre.length) +'#'+ Radisk.encode(k) + (u === val? '' : '='+ Radisk.encode(val)) +'\n';
- if(opt.chunk < f.text.length + enc.length){
+ if((opt.chunk < f.text.length + enc.length) && !(1 >= rad.count)){
f.text = '';
f.limit = Math.ceil(f.count/2);
f.count = 0;
@@ -171,15 +170,8 @@
if(!Radix.map(rad, f.each, true)){ f.write() }
}
- r.read = function(key, cb){
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- // TODO: BUG!!! If a node spans multiple file chunks, it won't return all!
- if(RAD){ // cache
+ r.read = function(key, cb, next){
+ if(RAD && !next){ // cache
var val = RAD(key);
if(u !== val){
return cb(u, val);
@@ -188,26 +180,32 @@
var g = function Get(){}, tmp;
g.lex = function(file){
file = (u === file)? u : decodeURIComponent(file);
- if(!file || file > key){
+ if(!file || file > (next || key)){
+ if(next){ g.file = file }
if(tmp = q[g.file]){
- tmp.push({key: key, ack: cb});
+ tmp.push({key: key, ack: cb, file: g.file});
return true;
}
- q[g.file] = [{key: key, ack: cb}];
+ q[g.file] = [{key: key, ack: cb, file: g.file}];
r.parse(g.file, g.it);
return true;
}
g.file = file;
}
g.it = function(err, disk){
- if(g.err = err){ Gun.log(err) }
+ if(g.err = err){ Gun.log('err', err) }
if(disk){ RAD = disk }
disk = q[g.file]; Gun.obj.del(q, g.file);
Gun.obj.map(disk, g.ack);
}
g.ack = function(as){
if(!as.ack){ return }
- as.ack(g.err, (RAD || noop)(as.key));
+ var tmp = as.key, data = (RAD || noop)(tmp), last = (RAD||{}).last;
+ if(data){ as.ack(g.err, data) }
+ else if(!as.file){ return as.ack(g.err, u) }
+ if(!last || last === tmp){ return } // is this correct?
+ if(last > tmp && 0 > last.indexOf(tmp)){ return }
+ r.read(tmp, as.ack, as.file);
}
opt.store.list(g.lex);
}
diff --git a/lib/radix.js b/lib/radix.js
index ae8731db..22264e76 100644
--- a/lib/radix.js
+++ b/lib/radix.js
@@ -2,6 +2,11 @@
function Radix(){
var radix = function(key, val, t){
+ key = ''+key;
+ if(!t && u !== val){
+ radix.last = (key < radix.last)? radix.last : key;
+ radix.count = (radix.count || 0) + 1;
+ }
t = t || radix[_] || (radix[_] = {});
var i = 0, l = key.length-1, k = key[i], at, tmp;
while(!(at = t[k]) && i < l){
diff --git a/lib/store.js b/lib/store.js
index 5445ca14..82b7cd44 100644
--- a/lib/store.js
+++ b/lib/store.js
@@ -1,4 +1,6 @@
-if(typeof window === "undefined"){
+if(typeof window !== "undefined"){
+ var Gun = window.Gun;
+} else {
var Gun = require('../gun');
}
@@ -18,10 +20,11 @@ Gun.on('opt', function(ctx){
opt.store = opt.store || (!opt.window && require('./rfs')(opt));
var rad = Radisk(opt);
- ctx.on('put', function(at){
- this.to.next(at);
- var id = at['#'], track = !at['@'], acks = track? 0 : u; // only ack non-acks.
- Gun.graph.is(at.put, null, function(val, key, node, soul){
+ ctx.on('put', function(msg){
+ this.to.next(msg);
+ var id = msg['#'], track = !msg['@'], acks = track? 0 : u; // only ack non-acks.
+ if(msg.rad && !track){ return } // don't save our own acks
+ Gun.graph.is(msg.put, null, function(val, key, node, soul){
if(track){ ++acks }
val = Radisk.encode(val)+'>'+Radisk.encode(Gun.state.is(node, key));
rad(soul+'.'+key, val, (track? ack : u));
@@ -30,7 +33,7 @@ Gun.on('opt', function(ctx){
acks--;
if(ack.err){ return }
if(ack.err = err){
- ctx.on('in', {'@': id, err: Gun.log(err)});
+ ctx.on('in', {'@': id, err: err});
return;
}
if(acks){ return }
@@ -38,15 +41,15 @@ Gun.on('opt', function(ctx){
}
});
- ctx.on('get', function(at){
- this.to.next(at);
- var id = at['#'], soul = at.get['#'], key = at.get['.']||'', tmp = soul+'.'+key, node;
+ ctx.on('get', function(msg){
+ this.to.next(msg);
+ var id = msg['#'], soul = msg.get['#'], key = msg.get['.']||'', tmp = soul+'.'+key, node;
rad(tmp, function(err, val){
if(val){
Radix.map(val, each);
if(!node){ each(val, key) }
}
- ctx.on('in', {'@': id, put: Gun.graph.node(node), err: err? err : u});
+ ctx.on('in', {'@': id, '#': key, put: Gun.graph.node(node), err: err? err : u, rad: Radix});
});
function each(val, key){
tmp = val.lastIndexOf('>');
diff --git a/lib/time.js b/lib/time.js
index 75b431f7..9025ab1f 100644
--- a/lib/time.js
+++ b/lib/time.js
@@ -1,4 +1,6 @@
-if(typeof window === "undefined"){ //Not in the browser, Include from node
+if(typeof window !== "undefined"){
+ var Gun = window.Gun;
+} else {
var Gun = require('../gun');
}
@@ -60,7 +62,7 @@ if(typeof window === "undefined"){ //Not in the browser, Include from node
function travel(cb, opt, b, gun){
var root = gun.back(-1), tmp;
(opt = Gun.num.is(opt)? {last: opt} : opt || {}).seen = opt.seen || {};
- var t = now();
+ var t = now(opt.start);
gun.on(function(data, key, msg, eve){
var at = msg.$._, id = at.link || at.soul || Gun.node.soul(data);
if(!id){ return }
diff --git a/test/radisk.html b/test/radisk.html
index 0083af92..4f51f9d9 100644
--- a/test/radisk.html
+++ b/test/radisk.html
@@ -6,29 +6,44 @@
+
+
+
+
+
+
\ No newline at end of file