From 9b56cbbacac1b44d129bd3ed56bf21f19a99e86d Mon Sep 17 00:00:00 2001 From: ansuz Date: Sat, 30 Jan 2016 17:05:59 +0100 Subject: [PATCH] guarantee ordering when using leveldb back end startup might be a little bit slower now but we shouldn't see "too much recursion" errors closes #6 (in theory) --- storage/lvl.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/storage/lvl.js b/storage/lvl.js index a77b8fe3e..b9c1c5bcc 100644 --- a/storage/lvl.js +++ b/storage/lvl.js @@ -59,12 +59,18 @@ module.exports.create = function(conf,cb){ getMessages: function(cName, cb){ /* get all messages relating to a channel */ getIndex(cName, function(index){ - for(var i=index;i>=0;i--){ - db.get(cName+'=>'+i,function(e,out){ - if(e) return console.error(e); - cb(out); - }); - } + var last = index, + i = 0, + next = function () { + db.get(cName+'=>'+i, function (e,out) { + if(e) return console.error(e); + cb(out); + if (++i <= last) { + next(); + } + }); + }; + next(); }); }, });