v1.18.x
Barış Soner Uşaklı 6 years ago
parent 74d0e88df3
commit 85a07e999b

@ -39,7 +39,11 @@ module.exports = function (db, module) {
if (!key.length) {
return setImmediate(callback, null, []);
}
key = { $in: key };
if (key.length > 1) {
key = { $in: key };
} else {
key = key[0];
}
}
var query = { _key: key };

@ -49,16 +49,7 @@ module.exports = function (Topics) {
if (params.term === 'alltime') {
var key = 'topics:' + params.sort;
if (params.cids) {
key = params.cids.map(function (cid) {
if (params.sort === 'recent') {
return 'cid:' + cid + ':tids:lastposttime';
} else if (params.sort === 'votes') {
return 'cid:' + cid + ':tids:votes';
} else if (params.sort === 'posts') {
return 'cid:' + cid + ':tids:posts';
}
return 'cid:' + cid + ':tids';
});
key = getCidSets(params.cids, params.sort);
}
db.getSortedSetRevRange(key, 0, 199, next);
@ -67,7 +58,7 @@ module.exports = function (Topics) {
}
},
function (tids, next) {
if (params.term !== 'alltime') {
if (params.term !== 'alltime' || (params.cids && params.sort !== 'recent')) {
sortTids(tids, params, next);
} else {
next(null, tids);
@ -79,6 +70,19 @@ module.exports = function (Topics) {
], callback);
}
function getCidSets(cids, sort) {
const keys = [];
cids.forEach(function (cid) {
if (sort === 'recent') {
keys.push('cid:' + cid + ':tids:lastposttime');
return;
}
keys.push('cid:' + cid + ':tids' + (sort ? ':' + sort : ''));
keys.push('cid:' + cid + ':tids:pinned');
});
return keys;
}
function sortTids(tids, params, callback) {
async.waterfall([
function (next) {

Loading…
Cancel
Save