handle empty set, add test

v1.18.x
Barış Soner Uşaklı 7 years ago
parent afa6c71b72
commit f8e219c323

@ -36,6 +36,9 @@ module.exports = function (db, module) {
}
if (Array.isArray(key)) {
if (!key.length) {
return setImmediate(callback, null, []);
}
key = { $in: key };
}

@ -4,6 +4,7 @@
var async = require('async');
var _ = require('lodash');
const db = require('../database');
var privileges = require('../privileges');
var search = require('../search');
@ -46,15 +47,10 @@ module.exports = function (Topics) {
Topics.getTopicTags(tid, next);
},
function (tags, next) {
async.map(tags, function (tag, next) {
Topics.getTagTids(tag, 0, -1, next);
}, next);
},
function (data, next) {
next(null, _.uniq(_.flatten(data)));
db.getSortedSetRevRange(tags.map(tag => 'tag:' + tag + ':topics'), 0, -1, next);
},
function (tids, next) {
tids = tids.map(Number);
tids = _.uniq(tids).map(Number);
privileges.topics.filterTids('read', tids, uid, next);
},
], callback);

@ -139,6 +139,14 @@ describe('Sorted Set methods', function () {
done();
});
});
it('should return empty array if keys is empty array', function (done) {
db.getSortedSetRange([], 0, -1, function (err, data) {
assert.ifError(err);
assert.deepStrictEqual(data, []);
done();
});
});
});
describe('getSortedSetRevRange()', function () {

Loading…
Cancel
Save