mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 01:26:16 +01:00
handle empty set, add test
This commit is contained in:
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user