mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: use getSortedSetsMembers to load followed tids
This commit is contained in:
@@ -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] || []);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user