From b5df5c0a9160745ffc092e6b21c724d6e2393bb5 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 9 Jul 2014 13:26:39 -0400 Subject: [PATCH] closes #1562, level session --- src/database/level.js | 4 +-- src/database/level/sorted.js | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/database/level.js b/src/database/level.js index f06fc8e4f0..f9b056e1ad 100644 --- a/src/database/level.js +++ b/src/database/level.js @@ -13,7 +13,7 @@ var winston = require('winston'), nconf = require('nconf'), path = require('path'), - express = require('express'), + session = require('express-session'), utils = require('./../../public/src/utils.js'), levelup, leveldown, @@ -32,7 +32,7 @@ try { levelup = require('levelup'); leveldown = require('leveldown'); - connectLevel = require('connect-leveldb')(express); + connectLevel = require('connect-leveldb')(session); } catch (err) { winston.error('Unable to initialize Level DB! Is Level DB installed? Error :' + err.message); process.exit(); diff --git a/src/database/level/sorted.js b/src/database/level/sorted.js index f84edd5e62..7d68a5cc59 100644 --- a/src/database/level/sorted.js +++ b/src/database/level/sorted.js @@ -167,4 +167,56 @@ module.exports = function(db, module) { callback(err, sets); }); }; + + module.getSortedSetUnion = function(sets, start, stop, callback) { + sortedSetUnion(sets, false, start, stop, callback); + }; + + module.getSortedSetRevUnion = function(sets, start, stop, callback) { + sortedSetUnion(sets, true, start, stop, callback); + }; + + function sortedSetUnion(sets, reverse, start, stop, callback) { + if (typeof start === 'function') { + callback = start; + start = 0; + stop = -1; + } else if (typeof stop === 'function') { + callback = stop; + stop = -1; + } + + async.map(sets, function(key, next) { + module.getListRange(key, 0, -1, next); + }, function(err, results) { + if (err) { + return callback(err); + } + + var data = {}; + + results.forEach(function(set) { + for(var i=0; i