diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index 2899a86188..2f48aeb75f 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -360,15 +360,22 @@ module.exports = function (module) { if (!Array.isArray(keys) || !keys.length) { return []; } - + const arrayOfKeys = keys.length > 1; + const projection = { _id: 0, value: 1 }; + if (arrayOfKeys) { + projection._key = 1; + } const data = await module.client.collection('objects').find({ - _key: keys.length === 1 ? keys[0] : { $in: keys }, - }, { projection: { _id: 0, _key: 1, value: 1 } }).toArray(); + _key: arrayOfKeys ? { $in: keys } : keys[0], + }, { projection: projection }).toArray(); - var sets = {}; - data.forEach(function (set) { - sets[set._key] = sets[set._key] || []; - sets[set._key].push(set.value); + if (!arrayOfKeys) { + return [data.map(item => item.value)]; + } + const sets = {}; + data.forEach(function (item) { + sets[item._key] = sets[item._key] || []; + sets[item._key].push(item.value); }); return keys.map(k => sets[k] || []); diff --git a/src/topics/unread.js b/src/topics/unread.js index a71fdada11..c08c3eb40a 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -177,9 +177,9 @@ module.exports = function (Topics) { } async function getFollowedTids(params) { - const tids = await db.getSortedSetRevRange('uid:' + params.uid + ':followed_tids', 0, -1); - const scores = await db.sortedSetScores('topics:recent', tids); - const data = tids.map((tid, index) => ({ value: tid, score: scores[index] })); + const tids = await db.getSortedSetsMembers(['uid:' + params.uid + ':followed_tids']); + const scores = await db.sortedSetScores('topics:recent', tids[0]); + const data = tids[0].map((tid, index) => ({ value: tid, score: scores[index] })); return data.filter(item => item.score > params.cutoff); }