closes #1562, level session

v1.18.x
barisusakli 11 years ago
parent 53d68be7c0
commit b5df5c0a91

@ -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();

@ -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<set.length; ++i) {
data[set[i].value] = data[set[i].value] || {value: set[i].value, score: 0};
data[set[i].value].score += parseInt(set[i].score, 10);
}
});
var returnData = [];
for(var key in data) {
if (data.hasOwnProperty(key)) {
returnData.push(data[key]);
}
}
returnData = returnData.sort(function(a, b) {
return reverse ? b.score - a.score : a.score - b.score;
}).map(function(item) {
return item.value;
});
callback(null, returnData);
});
}
};
Loading…
Cancel
Save